Fix flaky testTaskCancel_whenStreaming_andNotSuspended (#2355)

# Motivation
Currently `testTaskCancel_whenStreaming_andNotSuspended` is flaky since `didTerminate` can be called after the iterator is dropped. Fixes https://github.com/apple/swift-nio/issues/2354

# Modification
Let's modify that slightly so we hight the condition we want to hit.

# Result
No more flaky tests.
This commit is contained in:
Franz Busch 2023-01-25 14:09:22 +00:00 committed by GitHub
parent 417278754e
commit 45167b8006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -391,9 +391,16 @@ final class NIOAsyncSequenceProducerTests: XCTestCase {
let sequence = try XCTUnwrap(self.sequence)
let task: Task<Int?, Never> = Task {
let iterator = sequence.makeAsyncIterator()
return await iterator.next()
let value = await iterator.next()
// Sleeping here a bit to make sure we hit the case where
// we are streaming and still retain the iterator.
try? await Task.sleep(nanoseconds: 1_000_000)
return value
}
try await Task.sleep(nanoseconds: 1_000_000)
try await Task.sleep(nanoseconds: 2_000_000)
_ = self.source.yield(contentsOf: [1])