Skip to content

Commit 322365e

Browse files
committed
fix sync issue when running test in parallel
1 parent 14e80d9 commit 322365e

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Tests/AWSLambdaRuntimeTests/LambdaRuntimeTests.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,41 @@ struct LambdaRuntimeTests {
4141
)
4242

4343
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
44+
4445
// start the first runtime
4546
taskGroup.addTask {
46-
// ChannelError will be thrown when we cancel the task group
47-
await #expect(throws: ChannelError.self) {
48-
try await runtime1.run()
49-
}
47+
// will throw LambdaRuntimeError when run() is called second or ChannelError when cancelled
48+
try await runtime1.run()
5049
}
5150

5251
// wait a small amount to ensure runtime1 task is started
53-
// on GH Actions, it might take a bit longer to start the runtime
54-
try await Task.sleep(for: .seconds(2))
52+
try await Task.sleep(for: .seconds(0.5))
5553

56-
// Running the second runtime should trigger LambdaRuntimeError
57-
// start the first runtime
54+
// start the second runtime
5855
taskGroup.addTask {
59-
await #expect(throws: LambdaRuntimeError.self) {
60-
try await runtime2.run()
61-
}
56+
// will throw LambdaRuntimeError when run() is called second or ChannelError when cancelled
57+
try await runtime2.run()
58+
}
59+
60+
// get the first result (should be a LambdaRuntimeError)
61+
let error1 = try await #require(throws: (any Error).self) {
62+
try await taskGroup.next()
6263
}
6364

64-
// cancel runtime 1 / task 1
65+
// cancel the other task
6566
taskGroup.cancelAll()
67+
68+
// get the second result (should be a ChannelError)
69+
let error2 = try await #require(throws: (any Error).self) {
70+
try await taskGroup.next()
71+
}
72+
73+
#expect(error1 is LambdaRuntimeError, "First runtime should throw LambdaRuntimeError")
74+
#expect(error2 is ChannelError, "Second runtime should throw ChannelError")
6675
}
6776

6877
// wait a small amount to ensure everything is cancelled and cleanup
69-
try await Task.sleep(for: .seconds(1))
78+
try await Task.sleep(for: .seconds(0.5))
7079

7180
// Running the second runtime should work now
7281
try await withThrowingTaskGroup(of: Void.self) { taskGroup in

0 commit comments

Comments
 (0)