From f4f4e6a4258886ae755512e539ea837212cd3cea Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Sat, 31 Oct 2026 14:14:14 -0400 Subject: [PATCH] Keep Space cancellation tests suspended until cancelled --- Tests/ParcelEngineTests/SpaceCommandTests.swift | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 } -- knotmirror 0.0.1