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

fix: support parallel servers in tests #357

Merged
merged 1 commit into from
Jul 4, 2024
Merged

Conversation

giladchase
Copy link
Collaborator

@giladchase giladchase commented Jul 4, 2024

In order to add additional integration tests, the Web and RPC servers
must run on unique addresses, otherwise trying to create an additional
server will fail due to the socket already being in use.

This is achieved by selecting the port dynamically, through setting the
port as 0 (dynamic port), which local_addr then resolves into an
the actual port selected, that is, replacing 127.0.0.1:0 with
127.0.0.1:<available_port_that_was_bound_by_TcpListener>


This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Jul 4, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.80%. Comparing base (0075bb3) to head (cba6eb5).

Files Patch % Lines
crates/tests-integration/src/state_reader.rs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #357      +/-   ##
==========================================
- Coverage   80.84%   80.80%   -0.04%     
==========================================
  Files          35       35              
  Lines        1618     1620       +2     
  Branches     1618     1620       +2     
==========================================
+ Hits         1308     1309       +1     
  Misses        245      245              
- Partials       65       66       +1     

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

Copy link
Collaborator

@elintul elintul left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dafnamatsry, @giladchase, and @yair-starkware)


crates/tests-integration/src/integration_test_utils.rs line 85 at r1 (raw file):

}

/// Get a unique ip address and port for testing purposes.

Suggestion:

/// Returns a unique IP address and port for testing purposes.

crates/tests-integration/src/integration_test_utils.rs line 89 at r1 (raw file):

/// Tests run in parallel, so servers (like RPC or web) running on separate tests must have
/// different ports, otherwise the server will fail with "address already in use".
pub async fn available_socket() -> SocketAddr {

Suggestion:

get_available_socket

crates/tests-integration/src/integration_test_utils.rs line 94 at r1 (raw file):

        .expect("Failed to bind to address")
        .local_addr()
        .expect("Failed to get local address")

Converted your explanation above to documentation.

Suggestion:

    // Dinamically select port.
    // First, set the port to 0 (dynamic port).
    TcpListener::bind("127.0.0.1:0")
        .await
        .expect("Failed to bind to address")
        // Then, resolve to the actual selected port.
        .local_addr()
        .expect("Failed to get local address")

Copy link
Collaborator Author

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dafnamatsry, @elintul, and @yair-starkware)


crates/tests-integration/src/integration_test_utils.rs line 94 at r1 (raw file):

Previously, elintul (Elin) wrote…

Converted your explanation above to documentation.

🔥

@giladchase giladchase force-pushed the gilad/parallelize-servers branch from c269516 to fd11822 Compare July 4, 2024 10:02
Copy link
Collaborator

@elintul elintul left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dafnamatsry and @yair-starkware)

In order to add additional integration tests, the Web and RPC servers
must run on unique addresses, otherwise trying to create an additional
server will fail due to the socket already being in use.

This is achieved by selecting the port dynamically, through setting the
port as 0 (dynamic port), which `local_addr` then resolves into an
the actual port selected, that is, replacing `127.0.0.1:0` with
`127.0.0.1:<available_port_that_was_bound_by_TcpListener>`
@giladchase giladchase force-pushed the gilad/parallelize-servers branch from fd11822 to cba6eb5 Compare July 4, 2024 14:33
Copy link
Collaborator

@elintul elintul left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dafnamatsry and @yair-starkware)

@giladchase giladchase merged commit a106711 into main Jul 4, 2024
8 checks passed
@giladchase giladchase deleted the gilad/parallelize-servers branch July 4, 2024 15:01
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.

3 participants