From dded88acb9320e3f16a97073c84a139a56e0def5 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Thu, 21 Oct 2021 15:59:57 +0200 Subject: [PATCH] test: wait a bit for the given PID to die if it's still alive When playing around with the coverage-enabled build I kept hitting an issue where dnsmasq failed to start because the previous instance was still shutting down. This should, hopefully, help to mitigate that. --- test/test-network/systemd-networkd-tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 733a8d5aa55..4a358edcd27 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -3,6 +3,7 @@ # systemd-networkd tests import argparse +import errno import itertools import os import re @@ -483,6 +484,15 @@ def stop_by_pid_file(pid_file): with open(pid_file, 'r') as f: pid = f.read().rstrip(' \t\r\n\0') os.kill(int(pid), signal.SIGTERM) + for _ in range(25): + try: + os.kill(int(pid), 0) + print(f"PID {pid} is still alive, waiting...") + time.sleep(.2) + except OSError as e: + if e.errno == errno.ESRCH: + break + print(f"Unexpected exception when waiting for {pid} to die: {e.errno}") os.remove(pid_file) -- 2.47.3