diff --git a/Tests/ParcelEngineTests/SpaceCommandTests.swift b/Tests/ParcelEngineTests/SpaceCommandTests.swift index 72f21065..059b52c6 100644 --- a/Tests/ParcelEngineTests/SpaceCommandTests.swift +++ b/Tests/ParcelEngineTests/SpaceCommandTests.swift @@ -40,7 +40,13 @@ private final class FakeSpaceWorld: EngineSpaceWorld { onExecute?() if let error { throw error } if suspend { - do { try await Task.sleep(for: .seconds(10)) } catch { + // Suspension must not expire while other tests occupy the main actor. + let (stream, continuation) = AsyncStream.makeStream() + defer { continuation.finish() } + do { + for await _ in stream {} + try Task.checkCancellation() + } catch { cancelled = true throw error } @@ -167,11 +173,11 @@ struct SpaceCommandRoutingTests { let harness = try EngineHarness(spaceWorld: spaces) try await harness.start() let operation = Task { try await harness.engine.performConfigured(.spaceNext) } - for _ in 0..<1000 { - if !spaces.calls.isEmpty { break } - await Task.yield() + await withCheckedContinuation { continuation in + spaces.onExecute = { continuation.resume() } } - #expect(!spaces.calls.isEmpty) + spaces.onExecute = nil + try #require(!spaces.calls.isEmpty) await #expect(throws: IPCError.self) { try await harness.engine.performConfigured(.spaceNext) } await harness.engine.stop() await #expect(throws: CancellationError.self) { try await operation.value }