@@ -41,32 +41,41 @@ struct LambdaRuntimeTests {
41
41
)
42
42
43
43
try await withThrowingTaskGroup ( of: Void . self) { taskGroup in
44
+
44
45
// start the first runtime
45
46
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 ( )
50
49
}
51
50
52
51
// 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 ) )
55
53
56
- // Running the second runtime should trigger LambdaRuntimeError
57
- // start the first runtime
54
+ // start the second runtime
58
55
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 ( )
62
63
}
63
64
64
- // cancel runtime 1 / task 1
65
+ // cancel the other task
65
66
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 " )
66
75
}
67
76
68
77
// 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 ) )
70
79
71
80
// Running the second runtime should work now
72
81
try await withThrowingTaskGroup ( of: Void . self) { taskGroup in
0 commit comments