@testable import ParcelTestSupport // This only guards hung fixtures; injected schedulers own the deadlines under test. func waitForTestEvent( _ events: AsyncStream, matching condition: @escaping @Sendable (Value) -> Bool = { _ in true }, timeout: Duration = .seconds(30), label: String ) async throws { try await withThrowingTaskGroup(of: Void.self) { group in group.addTask { for await event in events { if condition(event) { return } } try Task.checkCancellation() throw E2EError(description: "Event stream ended before \(label)") } group.addTask { try await Task.sleep(for: timeout) throw E2EError(description: "Timed out waiting for \(label)") } defer { group.cancelAll() } try await group.next() } }