Fix flakey testHalfCloseOwnOutputWithPopulatedBuffer on iOS sim (#3551)

### Motivation

* `testHalfCloseOwnOutputWithPopulatedBuffer` asserts that writing to a
half-closed channel produces `ChannelError.outputClosed`. However, after
flushing the buffered write and the FIN, the remote peer can process
both and fully close the connection before the subsequent write is
processed. When this happens the channel is fully closed and the write
fails with `.ioOnClosedChannel` instead.
* This race seems to be more likely on iOS simulators in CI.

### Modifications

* Accept either `.outputClosed` or `.ioOnClosedChannel` as valid errors
from the post-half-close write.

### Result

* The test no longer flakes on iOS simulator CI runs.
This commit is contained in:
Rick Newton-Rogers authored and GitHub committed 2026-03-17 19:19:37 +00:00
1 parent e313684789
commit 0e7d4e9534
1 file changed
+9 -2
+9 -2
View File
@@ -282,9 +282,16 @@ class StreamChannelTest: XCTestCase {
// flush chan1's output
chan1.flush()
// Attempt to write a byte from chan1 to chan2 which should be refused after the close
// Attempt to write a byte from chan1 to chan2 which should be refused after the close.
// We expect `.outputClosed` from the half-close, but if the remote peer processes
// the FIN and closes before this write is processed, the channel may fully close
// and we get `.ioOnClosedChannel` instead.
XCTAssertThrowsError(try chan1.write(self.buffer).wait()) { error in
XCTAssertEqual(ChannelError.outputClosed, error as? ChannelError, "\(chan1)")
let channelError = error as? ChannelError
XCTAssertTrue(
channelError == .outputClosed || channelError == .ioOnClosedChannel,
"Unexpected error \(error) on \(chan1)"
)
}
// wait for the write to complete