Skip to content
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

tests: Fix a flaky protocol test #849

Merged
merged 1 commit into from
Nov 3, 2023
Merged

Conversation

msbrogli
Copy link
Member

@msbrogli msbrogli commented Nov 3, 2023

Motivation

The run_to_completion() method is designed to advance a test's clock until all scheduled calls are executed. This approach works well in isolation but presents issues in a simulation environment where multiple nodes share a single clock.

The crux of the problem emerges when a new node is created in the middle of a simulation. The create_peer() method invokes the run_to_completion(), which causes an unintended ripple effect: while the intention is to execute delayed calls only for the newly created node, the shared clock architecture means that the delayed calls for all nodes get executed.

In essence, while run_to_completion() aims to streamline the handling of delayed calls, its current design inadvertently interferes with the natural flow of the simulation, especially when new nodes are dynamically added.

This issue was causing flakiness in the test tests/p2p/test_protocol.py::SyncV2HathorProtocolTestCase::test_two_connections because the initialization of a new node was calling send_get_best_blockchain() multiple times due to a looping call. The number of times changes randomly so the asserts were failing randomly too.

Acceptance Criteria

  1. Modify create_peer() to stop calling run_to_completion(). It will just advance the clock once to execute delayed calls set by manager.start().
  2. Remove unnecessary and unstable asserts from tests/p2p/test_protocol.py::SyncV2HathorProtocolTestCase::test_two_connections.

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@msbrogli msbrogli requested a review from jansegre as a code owner November 3, 2023 09:15
@msbrogli msbrogli self-assigned this Nov 3, 2023
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (98121c4) 84.99% compared to head (89af93f) 85.00%.

❗ Current head 89af93f differs from pull request most recent head a289460. Consider uploading reports for the commit a289460 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #849   +/-   ##
=======================================
  Coverage   84.99%   85.00%           
=======================================
  Files         271      271           
  Lines       22368    22362    -6     
  Branches     3418     3416    -2     
=======================================
- Hits        19012    19009    -3     
+ Misses       2679     2676    -3     
  Partials      677      677           

see 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@msbrogli msbrogli requested a review from glevco November 3, 2023 15:51
@msbrogli msbrogli force-pushed the tests/flaky-protocol-tests branch from 89af93f to a289460 Compare November 3, 2023 17:49
@msbrogli msbrogli merged commit a289460 into master Nov 3, 2023
@msbrogli msbrogli deleted the tests/flaky-protocol-tests branch November 3, 2023 17:51
@jansegre jansegre mentioned this pull request Nov 13, 2023
2 tasks
This was referenced Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants