From 7fcf94d7b5d641068db99aad72bc13c38e93a7cf Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Tue, 17 Sep 2024 10:41:32 -0600 Subject: [PATCH] Add network namespace leak check Signed-off-by: Ed Santiago --- test/system/setup_suite.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/system/setup_suite.bash b/test/system/setup_suite.bash index fa7169a127..8a920c6141 100644 --- a/test/system/setup_suite.bash +++ b/test/system/setup_suite.bash @@ -35,6 +35,9 @@ function setup_suite() { # Canary file. Will be removed if any individual test fails. touch "$BATS_SUITE_TMPDIR/all-tests-passed" + + # Track network namespaces, so we can check for leaks at test end + ip netns list > $BATS_SUITE_TMPDIR/netns-pre } # Run at the very end of all tests. Useful for cleanup of non-BATS tmpdirs. @@ -49,6 +52,15 @@ function teardown_suite() { if [ $? -gt 0 ]; then exit_code=$((exit_code + 1)) fi + + # Network namespace leak check. List should match what we saw above. + echo + ip netns list > $BATS_SUITE_TMPDIR/netns-post + if ! diff -u $BATS_SUITE_TMPDIR/netns-{pre,post}; then + echo + echo "^^^^^ Leaks found in /run/netns ^^^^^" + exit_code=$((exit_code + 1)) + fi fi return $exit_code