]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: wait a bit for the given PID to die if it's still alive
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 21 Oct 2021 13:59:57 +0000 (15:59 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 21 Oct 2021 13:59:57 +0000 (15:59 +0200)
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

index 733a8d5aa55dcdcbedf065f51c02686dfc944c6c..4a358edcd271f92656e628e05fa4531ddf19140b 100755 (executable)
@@ -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)