mirror of
https://github.com/apple/swift-nio
synced 2026-11-24 04:37:54 +00:00
A DatagramChannelTest now waits for writes (#2905)
### Motivation: In `DatagramChannelTests.testChannelCanReportWritableBufferedBytesWithDataLargerThanSendBuffer` we assert that there are no buffered writable bytes immediately after a flush, however in some cases tests fail as this is not true. We suspect that this is because in some situations the kernel can be slow to drain the write buffer leading to racey behavior. ### Modifications: Wait for writes to complete before asserting that the buffer is emptied. ### Result: Tests should be more deterministic. Co-authored-by: Cory Benfield <lukasa@apple.com>
This commit is contained in:
1 parent
ea78d5aadc
commit
bee38dffe9
1 file changed
+4
-1
@@ -1689,6 +1689,9 @@ class DatagramChannelTests: XCTestCase {
|
||||
do {
|
||||
if i % 2 == 0 {
|
||||
self.firstChannel.flush()
|
||||
XCTAssertNoThrow(
|
||||
try EventLoopFuture.andAllSucceed(promises, on: self.firstChannel.eventLoop).wait()
|
||||
)
|
||||
let bufferedAmount = try self.firstChannel.getOption(.bufferedWritableBytes).wait()
|
||||
XCTAssertEqual(bufferedAmount, 0)
|
||||
} else {
|
||||
@@ -1701,9 +1704,9 @@ class DatagramChannelTests: XCTestCase {
|
||||
}
|
||||
|
||||
self.firstChannel.flush()
|
||||
XCTAssertNoThrow(try EventLoopFuture.andAllSucceed(promises, on: self.firstChannel.eventLoop).wait())
|
||||
let finalBufferedAmount = try self.firstChannel.getOption(.bufferedWritableBytes).wait()
|
||||
XCTAssertEqual(finalBufferedAmount, 0)
|
||||
XCTAssertNoThrow(try EventLoopFuture.andAllSucceed(promises, on: self.firstChannel.eventLoop).wait())
|
||||
let datagrams = try self.secondChannel.waitForDatagrams(count: writeCount)
|
||||
|
||||
XCTAssertEqual(datagrams.count, writeCount)
|
||||
|
||||
Reference in new issue
Block a user