Skip to content

core, send-tx-service, quic-client: switch tests to use non-overlapping socket bind api#6897

Merged
lijunwangs merged 6 commits intoanza-xyz:masterfrom
puhtaytow:core-send-tx-service-quic-client-non-overlapping-socket-bind-api-0
Jul 14, 2025
Merged

core, send-tx-service, quic-client: switch tests to use non-overlapping socket bind api#6897
lijunwangs merged 6 commits intoanza-xyz:masterfrom
puhtaytow:core-send-tx-service-quic-client-non-overlapping-socket-bind-api-0

Conversation

@puhtaytow
Copy link
Copy Markdown

Problem

A bunch of tests still relies on either hardcoded ports or bind_to_localhost and bind_to_unspecified. This creates flaky tests in cases where unique port ranges are needed.

Related to #6886 and #6895

Summary of Changes

This PR should close the topic of migration to non-overlapping bindings.

@mergify mergify Bot requested a review from a team July 9, 2025 16:22
@puhtaytow puhtaytow changed the title core, send-tx-service, quic-client: use non-overlapping socket bind api core, send-tx-service, quic-client: switch tests to use non-overlapping socket bind api Jul 9, 2025
@0xbrw
Copy link
Copy Markdown

0xbrw commented Jul 10, 2025

@lijunwangs when you get a chance, can you take a look at this?

@lijunwangs
Copy link
Copy Markdown

@lijunwangs when you get a chance, can you take a look at this?

@0xbrw will do

let port_range = localhost_port_range_for_tests();
(
bind_to_localhost().unwrap(),
bind_to(IpAddr::V4(Ipv4Addr::LOCALHOST), port_range.0).expect("should bind"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if it fail to bind the first port in the range?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it fail to bind the port, then indeed there is no retry mechanism. It would panic with the expect message, rendering the test as failed.

Since the localhost_port_range_for_tests, use two mechanisms to prevent overlapping of the ports in standard tests and nextest runners scenarios, the situation would be unlikely to happen in the CI scenario, but possible in e.g. local testing where one run tests, these bind socks but before returning being interrupted and then tests being run again before releasing the previously allocated port or when the port was already in use.

This are the top of my head scenarios. Do you suggest to apply changes to cover edge cases like this?

Thank you for the question 🙏 🍀

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lijun, this should literally be impossible. If it ever happens, we fix localhost_port_range_for_tests to do its job.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work when the unit tests are executed in parallel?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, as long as you use cargo test or cargo nextest. I have not tested with other test runners.

@alexpyattaev alexpyattaev added the CI Pull Request is ready to enter CI label Jul 11, 2025
@anza-team anza-team removed the CI Pull Request is ready to enter CI label Jul 11, 2025
Comment thread core/src/banking_simulation.rs Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 11, 2025

Codecov Report

❌ Patch coverage is 41.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.2%. Comparing base (33f060d) to head (d8c012d).
⚠️ Report is 2973 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6897   +/-   ##
=======================================
  Coverage    83.2%    83.2%           
=======================================
  Files         852      852           
  Lines      376974   376982    +8     
=======================================
+ Hits       313890   313912   +22     
+ Misses      63084    63070   -14     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@puhtaytow
Copy link
Copy Markdown
Author

btw @alexpyattaev added the missing repair_service

@alexpyattaev alexpyattaev added the CI Pull Request is ready to enter CI label Jul 11, 2025
@anza-team anza-team removed the CI Pull Request is ready to enter CI label Jul 11, 2025
Copy link
Copy Markdown

@alexpyattaev alexpyattaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you! @lijunwangs are you happy with this one?

@lijunwangs lijunwangs merged commit fac7555 into anza-xyz:master Jul 14, 2025
43 checks passed
@puhtaytow
Copy link
Copy Markdown
Author

Thank you @alexpyattaev @lijunwangs 🙏 🙏

@puhtaytow puhtaytow deleted the core-send-tx-service-quic-client-non-overlapping-socket-bind-api-0 branch July 14, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants