-
Notifications
You must be signed in to change notification settings - Fork 189
fix: Make test_kbucket_split_behavior more reliable #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
add checking peer_id in indentify
- Add peer ID validation to prevent peer ID spoofing attacks - Reject signed peer records where peer ID doesn't match sender - Optimize peer ID comparison (direct comparison instead of string conversion) - Add comprehensive test for peer ID validation - Update docstrings with security information - Add newsfragment for issue #958 This addresses CVE-2023-40583 equivalent vulnerability.
Fix flaky test by ensuring mock_host.new_stream raises an exception so that ping operations fail consistently. This allows peers to be added when buckets are full, which is necessary for the test to pass. The test was failing intermittently in CI/CD because the ping behavior was unpredictable when new_stream was not properly mocked. This simulates real production behavior where new_stream() fails for unreachable peers, allowing the routing table to replace unresponsive peers as per Kademlia protocol specifications. Fixes #1032
|
Hi @seetadev and @sumanjeet0012, I've investigated the flaky test issue you mentioned in discussion #1023 regarding Root CauseThe test was flaky because the SolutionI've created a fix that mocks
PR CreatedI've opened PR #1033 with the fix. The test now passes consistently, and all other tests remain unaffected. Could you please review when you have a chance? The fix is minimal and focused on making the test more reliable. Thanks! |
|
Excellent work, @acul71 👏 This is a clean, well-reasoned fix to one of the more persistent CI/CD issues we’ve been seeing with test_kbucket_split_behavior. Your analysis of the root cause — particularly the insight that mock_host.new_stream() wasn’t properly mocked and was introducing nondeterministic behavior — is spot on. The solution of explicitly mocking new_stream() to raise an exception makes perfect sense. It brings the test behavior closer to real-world scenarios, where peers can be unreachable and ping attempts fail. This approach not only stabilizes the test but also improves the accuracy of how the routing table logic is validated against actual Kademlia behavior. It’s great to see that you verified consistency across multiple runs and ensured that all other tests remained unaffected. Thanks for taking the time to dig into the underlying issue and provide a production-aligned fix. 🚀 Looks ready for merge. |
Problem
The test
test_kbucket_split_behaviorintests/core/kad_dht/test_unit_routing_table.pywas failing intermittently in CI/CD, as reported in discussion #1023 and issue #1032.Root Cause
The
mock_hostfixture in theTestRoutingTableclass didn't properly mockhost.new_stream(). When a bucket is full, theKBucket.add_peer()method tries to ping the oldest peer using_ping_peer(), which callshost.new_stream(). Without proper mocking, the behavior was unpredictable, causing intermittent test failures.Solution
Mock
host.new_stream()in theTestRoutingTable.mock_hostfixture to raise an exception, simulating unresponsive peers. This makes the test deterministic and matches real production behavior wherenew_stream()fails for unreachable peers.Changes
host.new_stream = AsyncMock(side_effect=Exception("Mock stream error"))to themock_hostfixtureTesting
Related