git » chasquid » commit 9b3f7ca

test: Wait for children to exit before finishing an integration test

author Alberto Bertogli
2026-10-03 16:35:56 UTC
committer Alberto Bertogli
2026-10-03 16:35:56 UTC
parent d74e6e3d2b63eb2bef7cb941b4f696f72c6add33

test: Wait for children to exit before finishing an integration test

Some integration tests start servers on predictable ports, and then the
servers are killed at exit.

However, we currently don't want for them to die. This can cause races
where the next test starts while the previous daemons are still in the
process of exiting, causing flakiness.

This patch fixes the problem by waiting for the child processes to exit
before exiting the test.

test/util/lib.sh +5 -1

diff --git a/test/util/lib.sh b/test/util/lib.sh
index dcb4265..f0edcfa 100644
--- a/test/util/lib.sh
+++ b/test/util/lib.sh
@@ -26,7 +26,11 @@ function init() {
 	# Set traps to kill our subprocesses when we exit (for any reason).
 	trap ":" TERM      # Avoid the EXIT handler from killing bash.
 	trap "exit 2" INT  # Ctrl-C, make sure we fail in that case.
-	trap "kill 0" EXIT # Kill children on exit.
+	# Kill children on exit, and wait for them to finish, so they don't
+	# interfere with the next test (e.g. by still listening on a port).
+	# "wait" returns early (and with an error) if we get a signal while
+	# waiting, so we loop until it completes.
+	trap "kill 0; until wait; do :; done" EXIT
 }
 
 function chasquid() {