Skip to content

Rewrite, update, and refactor sockets-related tests#768

Open
alexcrichton wants to merge 1 commit intoWebAssembly:mainfrom
alexcrichton:refactor-networking-tests
Open

Rewrite, update, and refactor sockets-related tests#768
alexcrichton wants to merge 1 commit intoWebAssembly:mainfrom
alexcrichton:refactor-networking-tests

Conversation

@alexcrichton
Copy link
Collaborator

In #762 I'm seeing an error related to EADDRINUSE which I can't reproduce locally. Tests currently all use the same port which means that they are required to be run serially and additionally may run into this risk if the port happens to already be taken. I don't really know what's going on in CI, but I wanted to nevertheless refactor these tests.

This commit rearchitects, rewrites, and fixes sockets-related tests. Changes here are:

  • Servers now print the port they're listening to. Clients read this port and then connect to that port. This orchestration happens through some specially crafted bash and CMake, similar to before. All tests now bind to port 0 to get an OS-assigned port instead of picking a port.

  • All tests are now ungated, notably enabling some nonblocking I/O tests that were previously gated.

  • A number of tests are refactored or updated to be less flaky. Many tests were failing nondeterministically locally due to how the test was constructed and assuming certain things were ready when they may not be. Some tests were entirely rewritten, such as sockets-nonblocking-multiple.c, while others were only lightly refactored to poll in a few more places.

  • All tests are updated to pass in less than 100ms. Some tests before hung for awhile as timeouts were reached for example, but this wasn't a necessary part of the test. Other tests for nonblocking I/O had many calls to poll with a number of them reaching the timeout. These are rewritten to use a single call to poll with no timeout which enables the test to progress much faster as timeouts are never reached.

Overall the intent is that the sockets-related tests are more comprehensive now, more robust and/or less flaky, and work in more environments.

In WebAssembly#762 I'm seeing an error related to `EADDRINUSE` which I can't
reproduce locally. Tests currently all use the same port which means
that they are required to be run serially and additionally may run into
this risk if the port happens to already be taken. I don't really know
what's going on in CI, but I wanted to nevertheless refactor these tests.

This commit rearchitects, rewrites, and fixes sockets-related tests.
Changes here are:

* Servers now print the port they're listening to. Clients read this
  port and then connect to that port. This orchestration happens through
  some specially crafted bash and CMake, similar to before. All tests
  now bind to port 0 to get an OS-assigned port instead of picking a port.

* All tests are now ungated, notably enabling some nonblocking I/O tests
  that were previously gated.

* A number of tests are refactored or updated to be less flaky. Many
  tests were failing nondeterministically locally due to how the test
  was constructed and assuming certain things were ready when they may
  not be. Some tests were entirely rewritten, such as
  `sockets-nonblocking-multiple.c`, while others were only lightly
  refactored to `poll` in a few more places.

* All tests are updated to pass in less than 100ms. Some tests before
  hung for awhile as timeouts were reached for example, but this wasn't
  a necessary part of the test. Other tests for nonblocking I/O had many
  calls to `poll` with a number of them reaching the timeout. These are
  rewritten to use a single call to `poll` with no timeout which enables
  the test to progress much faster as timeouts are never reached.

Overall the intent is that the sockets-related tests are more
comprehensive now, more robust and/or less flaky, and work in more
environments.
@alexcrichton alexcrichton requested a review from dicej March 6, 2026 04:23
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.

1 participant