Skip to content

fix: stabilize flaky container-kill assertion tests#172

Merged
mensfeld merged 4 commits intomasterfrom
fix/stabilize-flaky-kill-assertions
Feb 28, 2026
Merged

fix: stabilize flaky container-kill assertion tests#172
mensfeld merged 4 commits intomasterfrom
fix/stabilize-flaky-kill-assertions

Conversation

@mensfeld
Copy link
Owner

Summary

  • Replace static time.sleep() + single state check with 15-iteration retry loops (1s each) in four container-kill assertion tests
  • Fix test_reverse_shell_detection to use the loop result directly instead of re-checking state after daemon termination
  • Matches the proven retry pattern already used in test_veth_zone_binding_cleaned_on_auto_kill

Tests fixed:

  • test_reverse_shell_detection (test_security_monitoring.py)
  • test_container_killed_on_metadata_access (test_nft_monitoring.py)
  • test_firewall_rules_cleaned_on_auto_kill (test_nft_monitoring.py)
  • test_nft_rules_cleaned_on_auto_kill (test_nft_monitoring.py)

Test plan

  • CI monitoring-threats job passes
  • CI monitoring-nft job passes

Integration tests for container kill detection used fixed time.sleep()
calls followed by a single state check, causing flaky failures on slow
CI runners. Replace with 15-iteration retry loops (1s sleep each) that
poll container state, matching the proven pattern already used in
test_veth_zone_binding_cleaned_on_auto_kill.

Also fix test_reverse_shell_detection to use the loop result directly
for its assertion instead of re-checking state after daemon termination.
After a container is killed, the firewall and NFT rule cleanup happens
asynchronously. Add 15-iteration retry loops (1s sleep) to the rule
cleanup assertions in test_nft_rules_cleaned_on_auto_kill and
test_firewall_rules_cleaned_on_auto_kill to avoid flaky failures.
test_reverse_shell_detection used time.sleep(8) to wait for container
creation, which is insufficient when the test runs first (before the
image is cached). Replace with a 30-iteration polling loop that waits
for the container to reach Running state.
@mensfeld mensfeld merged commit c199898 into master Feb 28, 2026
22 of 24 checks passed
@mensfeld mensfeld deleted the fix/stabilize-flaky-kill-assertions branch February 28, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant