fix: stabilize flaky container-kill assertion tests#172
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
time.sleep()+ single state check with 15-iteration retry loops (1s each) in four container-kill assertion teststest_reverse_shell_detectionto use the loop result directly instead of re-checking state after daemon terminationtest_veth_zone_binding_cleaned_on_auto_killTests 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
monitoring-threatsjob passesmonitoring-nftjob passes