mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 05:28:00 +00:00
Refactor shutdown test into more helper functions
Improve code readability by splitting the test into more functions. Some could be re-used later on for more general-purpose subprocess handling or named checks.
This commit is contained in:
parent
8d9bd808b1
commit
9d64f1c1ed
@ -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,15 @@ 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, "named isn't running"
|
||||||
assert named_proc.poll() is None
|
assert wait_for_named_loaded(resolver)
|
||||||
# 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)
|
|
||||||
|
|
||||||
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
|
|
||||||
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()
|
|
||||||
|
|
||||||
assert is_dead
|
|
||||||
# Ensures that named exited gracefully.
|
|
||||||
# If it crashed (abort()) exitcode will be non zero.
|
|
||||||
assert named_proc.returncode == 0
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user