Fix flaky test in NIOAsyncWriter (#2431)

* Fix flaky test in NIOAsyncWriter

# Motivation
We had flaky test in the writer where we were relying on some timing.

# Modification
Change the test so that it is deterministic.

# Result
Fixes https://github.com/apple/swift-nio/issues/2427

* Update allocation counters
This commit is contained in:
Franz Busch 2023-05-31 10:53:54 +02:00 committed by GitHub
parent 5768317b70
commit b22575ac96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 20 deletions

View File

@ -130,31 +130,19 @@ final class NIOAsyncWriterTests: XCTestCase {
}
func testWriterDeinitialized_whenStreaming() async throws {
Task { [writer] in
try await writer!.yield("message1")
}
try await Task.sleep(nanoseconds: 1_000_000)
try await writer.yield("message1")
self.writer = nil
XCTAssertEqual(self.delegate.didTerminateCallCount, 1)
}
func testWriterDeinitialized_whenWriterFinished() async throws {
self.sink.setWritability(to: false)
Task { [writer] in
try await writer!.yield("message1")
}
try await Task.sleep(nanoseconds: 1_000_000)
try await writer.yield("message1")
self.writer.finish()
self.writer = nil
XCTAssertEqual(self.delegate.didYieldCallCount, 0)
XCTAssertEqual(self.delegate.didTerminateCallCount, 0)
XCTAssertEqual(self.delegate.didYieldCallCount, 1)
XCTAssertEqual(self.delegate.didTerminateCallCount, 1)
}
func testWriterDeinitialized_whenFinished() async throws {

View File

@ -34,13 +34,13 @@ services:
- MAX_ALLOCS_ALLOWED_1000_getHandlers=8050
- MAX_ALLOCS_ALLOWED_1000_getHandlers_sync=36
- MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=26400
- MAX_ALLOCS_ALLOWED_1000_rst_connections=147000
- MAX_ALLOCS_ALLOWED_1000_rst_connections=148000
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4050
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=154050
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=155050
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=6050
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=2050
- MAX_ALLOCS_ALLOWED_1000_udpconnections=77050
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=399000
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=401000
- MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=2050
- MAX_ALLOCS_ALLOWED_creating_10000_headers=0
- MAX_ALLOCS_ALLOWED_decode_1000_ws_frames=2050
@ -61,7 +61,7 @@ services:
- MAX_ALLOCS_ALLOWED_get_100000_headers_canonical_form_trimming_whitespace_from_short_string=700050
- MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=0
- MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=6050
- MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=341
- MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=343
- MAX_ALLOCS_ALLOWED_read_10000_chunks_from_file=140050
- MAX_ALLOCS_ALLOWED_schedule_10000_tasks=50100
- MAX_ALLOCS_ALLOWED_schedule_and_run_10000_tasks=50050