mirror of
https://github.com/apple/swift-nio
synced 2026-11-22 04:30:41 +00:00
### Motivation: One of my project uses `NIOHTTP1TestServer` for testing and for responses that contain the `content-length` header + `connection: close`, the test was flaky - failing intermittently, because the client closed the connection before the test managed to submit `.end` to the test server. The cause was a race condition between the test and the client's and server's threads hosting their respective event loops. ### Modifications: Now `NIOHTTP1TestServer` captures the channel that sent the `.head`, and even once `currentClientChannel` changes (but before the next `.head` is sent), when a call to send `.end` comes in, uses the channel associated with the previous `.head`, rather than reading `currentClientChannel`. This test is skipped on Darwin as it requires the platform to detect early EOF. ### Result: More reliable tests that involve two requests that come in at once (in a deterministic order), when the second one is parked and ready right after the first one finishes.