mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 15:45:25 +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:
@@ -95,7 +95,7 @@ def do_work(named_proc, resolver, rndc_cmd, kill_method, n_workers, n_queries):
|
|||||||
)
|
)
|
||||||
|
|
||||||
qname = relname + ".test"
|
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
|
elif shutdown: # We attempt to stop named in the middle
|
||||||
shutdown = False
|
shutdown = False
|
||||||
if kill_method == "rndc":
|
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
|
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):
|
def test_named_shutdown(named_port, control_port):
|
||||||
# pylint: disable-msg=too-many-locals
|
# pylint: disable-msg=too-many-locals
|
||||||
cfg_dir = os.path.join(os.getcwd(), "resolver")
|
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"):
|
for kill_method in ("rndc", "sigterm"):
|
||||||
named_cmdline = [named, "-c", cfg_file, "-f"]
|
named_cmdline = [named, "-c", cfg_file, "-f"]
|
||||||
with subprocess.Popen(named_cmdline, cwd=cfg_dir) as named_proc:
|
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:
|
try:
|
||||||
resolver.resolve("version.bind", "TXT", "CH")
|
assert named_proc.poll() is None, "named isn't running"
|
||||||
break
|
assert wait_for_named_loaded(resolver)
|
||||||
except (dns.resolver.NoNameservers, dns.exception.Timeout):
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
do_work(
|
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,
|
||||||
)
|
)
|
||||||
|
assert wait_for_proc_termination(named_proc)
|
||||||
# Wait named to exit for a maximum of MAX_TIMEOUT seconds.
|
assert named_proc.returncode == 0, "named crashed"
|
||||||
MAX_TIMEOUT = 10
|
finally: # Ensure named is terminated in case of an exception
|
||||||
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:
|
|
||||||
named_proc.kill()
|
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
|
|
||||||
|
Reference in New Issue
Block a user