2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Merge branch 'tkrizek/shutdown-test-exc-handling' into 'main'

Ensure named always terminates in the shutdown test

See merge request isc-projects/bind9!7819
This commit is contained in:
Tom Krizek
2023-05-10 10:54:48 +00:00

View File

@@ -95,7 +95,7 @@ def do_work(named_proc, resolver, rndc_cmd, kill_method, n_workers, n_queries):
)
qname = relname + ".test"
futures[executor.submit(resolver.query, qname, "A")] = tag
futures[executor.submit(resolver.resolve, qname, "A")] = tag
elif shutdown: # We attempt to stop named in the middle
shutdown = False
if kill_method == "rndc":
@@ -131,6 +131,31 @@ def do_work(named_proc, resolver, rndc_cmd, kill_method, n_workers, n_queries):
assert ret_code == 0
def wait_for_named_loaded(resolver, retries=10):
for _ in range(retries):
try:
resolver.resolve("version.bind", "TXT", "CH")
return True
except (dns.resolver.NoNameservers, dns.exception.Timeout):
time.sleep(1)
return False
def wait_for_proc_termination(proc, max_timeout=10):
for _ in range(max_timeout):
if proc.poll() is not None:
return True
time.sleep(1)
proc.send_signal(signal.SIGABRT)
for _ in range(max_timeout):
if proc.poll() is not None:
return True
time.sleep(1)
return False
def test_named_shutdown(named_port, control_port):
# pylint: disable-msg=too-many-locals
cfg_dir = os.path.join(os.getcwd(), "resolver")
@@ -164,40 +189,18 @@ def test_named_shutdown(named_port, control_port):
for kill_method in ("rndc", "sigterm"):
named_cmdline = [named, "-c", cfg_file, "-f"]
with subprocess.Popen(named_cmdline, cwd=cfg_dir) as named_proc:
# Ensure named is running
assert named_proc.poll() is None
# wait for named to finish loading
for _ in range(10):
try:
resolver.resolve("version.bind", "TXT", "CH")
break
except (dns.resolver.NoNameservers, dns.exception.Timeout):
time.sleep(1)
assert named_proc.poll() is None, "named isn't running"
assert wait_for_named_loaded(resolver)
do_work(
named_proc, resolver, rndc_cmd, kill_method, n_workers=12, n_queries=16
named_proc,
resolver,
rndc_cmd,
kill_method,
n_workers=12,
n_queries=16,
)
# Wait named to exit for a maximum of MAX_TIMEOUT seconds.
MAX_TIMEOUT = 10
is_dead = False
for _ in range(MAX_TIMEOUT):
if named_proc.poll() is not None:
is_dead = True
break
time.sleep(1)
if not is_dead:
named_proc.send_signal(signal.SIGABRT)
for _ in range(MAX_TIMEOUT):
if named_proc.poll() is not None:
is_dead = True
break
time.sleep(1)
if not is_dead:
assert wait_for_proc_termination(named_proc)
assert named_proc.returncode == 0, "named crashed"
finally: # Ensure named is terminated in case of an exception
named_proc.kill()
assert is_dead
# Ensures that named exited gracefully.
# If it crashed (abort()) exitcode will be non zero.
assert named_proc.returncode == 0