Skip to content

Commit

Permalink
Fix flaky testTaskCancel_whenStreaming_andNotSuspended (#2355)
Browse files Browse the repository at this point in the history
# Motivation
Currently `testTaskCancel_whenStreaming_andNotSuspended` is flaky since `didTerminate` can be called after the iterator is dropped. Fixes #2354

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

# Result
No more flaky tests.
  • Loading branch information
FranzBusch authored Jan 25, 2023
1 parent 4172787 commit 45167b8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Tests/NIOCoreTests/AsyncSequences/NIOAsyncSequenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit 45167b8

Please sign in to comment.