import Testing @testable import ParcelTestSupport struct TestEventsTests { @Test func skipsUnrelatedBufferedEventsAndLeavesLaterEventsUnread() async throws { let events = AsyncStream.makeStream() for value in 1...3 { events.continuation.yield(value) } try await waitForTestEvent(events.stream, matching: { $0 == 2 }, label: "second write") var iterator = events.stream.makeAsyncIterator() #expect(await iterator.next() == 3) } @Test func finishedStreamWithoutMatchingEventFails() async { let events = AsyncStream.makeStream() events.continuation.yield(1) events.continuation.finish() await #expect(throws: E2EError.self) { try await waitForTestEvent(events.stream, matching: { $0 == 2 }, label: "second write") } } @Test func timeoutCancelsPendingRead() async { let events = AsyncStream.makeStream() await #expect(throws: E2EError.self) { try await waitForTestEvent(events.stream, timeout: .zero, label: "missing write") } } @Test func cancellationPropagatesWithoutASecondIssue() async { let events = AsyncStream.makeStream() let task = Task { try await waitForTestEvent(events.stream, label: "cancelled write") } task.cancel() await #expect(throws: CancellationError.self) { try await task.value } } }