Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import Foundationimport Testing
@testable import ParcelTestSupport
struct ProcessExitWaiterTests { @Test(arguments: [Int32(0), 7, -1], [Duration.seconds(4), .seconds(8)]) func recordedExitSurvivesDelayedConsumption(status: Int32, elapsed: Duration) async throws { let start = ContinuousClock.now let waiter = ProcessExitWaiter() waiter.record(status: status, at: start.advanced(by: elapsed)) let observed = try await waiter.wait( for: "fixture", timeout: .seconds(8), now: start, sleep: { _ in }) #expect(observed == status) }
@Test func lateExitDoesNotTurnTimeoutIntoSuccess() async { let start = ContinuousClock.now let waiter = ProcessExitWaiter() waiter.record(status: 0, at: start.advanced(by: .seconds(9))) await #expect(throws: E2EError.self) { try await waiter.wait(for: "late fixture", timeout: .seconds(8), now: start, sleep: { _ in }) } }
@Test func timeoutWithoutExitCancelsThePendingStreamRead() async { let waiter = ProcessExitWaiter() do { _ = try await waiter.wait(for: "missing fixture", timeout: .seconds(8), sleep: { _ in }) Issue.record("A missing exit must time out") } catch { #expect(String(describing: error) == "Timed out waiting for missing fixture") } }
@Test func firstExitWinsOverRepeatedCallbacks() async throws { let waiter = ProcessExitWaiter() waiter.record(status: 7) waiter.record(status: 0) let status = try await waiter.wait(for: "fixture", timeout: .seconds(8), sleep: { _ in }) #expect(status == 7) }
@Test func cancellationStopsTheStreamAndTimeout() async { let waiter = ProcessExitWaiter() let (started, continuation) = AsyncStream<Void>.makeStream() let task = Task { try await waiter.wait( for: "cancelled fixture", timeout: .seconds(8), sleep: { duration in continuation.yield(()) try await Task.sleep(for: duration) }) } var iterator = started.makeAsyncIterator() #expect(await iterator.next() != nil) task.cancel() await #expect(throws: CancellationError.self) { try await task.value } }}