@@ -44,26 +44,32 @@ struct BreezeLambdaWebHookServiceTests {
44
44
@Test ( " Service creates HTTP client with correct timeout configuration " )
45
45
func serviceCreatesHTTPClientWithCorrectConfig( ) async throws {
46
46
try await testGracefulShutdown { gracefulShutdownTestTrigger in
47
+ let ( gracefulStream, continuation) = AsyncStream< Void> . makeStream( )
47
48
try await withThrowingTaskGroup ( of: Void . self) { group in
48
49
let logger = Logger ( label: " test " )
49
50
let config = BreezeHTTPClientConfig ( timeout: . seconds( 30 ) , logger: logger)
50
51
let sut = BreezeLambdaWebHookService < MockHandler > ( config: config)
51
-
52
- await withTaskCancellationOrGracefulShutdownHandler {
53
- group. addTask {
52
+ group. addTask {
53
+ try await Task . sleep ( nanoseconds: 1_000_000_000 )
54
+ gracefulShutdownTestTrigger. triggerGracefulShutdown ( )
55
+ }
56
+ group. addTask {
57
+ try await withGracefulShutdownHandler {
54
58
try await sut. run ( )
59
+ print ( " BreezeLambdaAPIService started successfully " )
60
+ } onGracefulShutdown: {
61
+ logger. info ( " On Graceful Shutdown " )
62
+ continuation. yield ( )
63
+ continuation. finish ( )
55
64
}
56
- } onCancelOrGracefulShutdown: {
57
- gracefulShutdownTestTrigger. triggerGracefulShutdown ( )
58
- logger. info ( " On Graceful Shutdown " )
59
65
}
60
-
61
- try await Task . sleep ( nanoseconds : 1_000_000_000 )
62
- group . cancelAll ( )
63
-
64
- let handlerContext = try #require ( await sut . handlerContext )
65
- #expect ( handlerContext . httpClient . configuration . timeout . read == . seconds ( 30 ) )
66
- #expect ( handlerContext . httpClient . configuration . timeout . connect == . seconds ( 30 ) )
66
+ for await _ in gracefulStream {
67
+ logger . info ( " Graceful shutdown stream received " )
68
+ let handlerContext = try #require ( await sut . handlerContext )
69
+ #expect ( handlerContext . httpClient . configuration . timeout . read == . seconds ( 30 ) )
70
+ #expect ( handlerContext . httpClient . configuration . timeout . connect == . seconds ( 30 ) )
71
+ group . cancelAll ( )
72
+ }
67
73
}
68
74
}
69
75
}
@@ -86,36 +92,39 @@ struct BreezeLambdaWebHookServiceTests {
86
92
@Test ( " Handler delegates to specific handler implementation " )
87
93
func handlerDelegatesToImplementation( ) async throws {
88
94
try await testGracefulShutdown { gracefulShutdownTestTrigger in
95
+ let ( gracefulStream, continuation) = AsyncStream< Void> . makeStream( )
89
96
try await withThrowingTaskGroup ( of: Void . self) { group in
90
-
91
97
let logger = Logger ( label: " test " )
92
98
let config = BreezeHTTPClientConfig ( timeout: . seconds( 30 ) , logger: logger)
93
99
let sut = BreezeLambdaWebHookService < MockHandler > ( config: config)
94
-
100
+ group. addTask {
101
+ try await Task . sleep ( nanoseconds: 1_000_000_000 )
102
+ gracefulShutdownTestTrigger. triggerGracefulShutdown ( )
103
+ }
95
104
group. addTask {
96
105
try await withGracefulShutdownHandler {
97
106
try await sut. run ( )
107
+ print ( " BreezeLambdaAPIService started successfully " )
98
108
} onGracefulShutdown: {
99
109
logger. info ( " On Graceful Shutdown " )
110
+ continuation. yield ( )
111
+ continuation. finish ( )
100
112
}
101
113
}
102
- group. addTask {
103
- try await Task . sleep ( nanoseconds: 1_000_000_000 )
104
- gracefulShutdownTestTrigger. triggerGracefulShutdown ( )
114
+ for await _ in gracefulStream {
115
+ logger. info ( " Graceful shutdown stream received " )
116
+ let createRequest = try Fixtures . fixture ( name: Fixtures . getWebHook, type: " json " )
117
+ let event = try decoder. decode ( APIGatewayV2Request . self, from: createRequest)
118
+ let context = LambdaContext ( requestID: " req1 " , traceID: " trace1 " , invokedFunctionARN: " " , deadline: . now( ) , logger: logger)
119
+
120
+ let response = try await sut. handler ( event: event, context: context)
121
+ let handlerContext = try #require( await sut. handlerContext)
122
+ #expect( response. statusCode == 200 )
123
+ #expect( response. body == " Mock response " )
124
+ #expect( handlerContext. httpClient. configuration. timeout. read == . seconds( 30 ) )
125
+ #expect( handlerContext. httpClient. configuration. timeout. connect == . seconds( 30 ) )
126
+ group. cancelAll ( )
105
127
}
106
-
107
- let createRequest = try Fixtures . fixture ( name: Fixtures . getWebHook, type: " json " )
108
- let event = try decoder. decode ( APIGatewayV2Request . self, from: createRequest)
109
- let context = LambdaContext ( requestID: " req1 " , traceID: " trace1 " , invokedFunctionARN: " " , deadline: . now( ) , logger: logger)
110
-
111
- let response = try await sut. handler ( event: event, context: context)
112
- let handlerContext = try #require( await sut. handlerContext)
113
- #expect( response. statusCode == 200 )
114
- #expect( response. body == " Mock response " )
115
- #expect( handlerContext. httpClient. configuration. timeout. read == . seconds( 30 ) )
116
- #expect( handlerContext. httpClient. configuration. timeout. connect == . seconds( 30 ) )
117
-
118
- group. cancelAll ( )
119
128
}
120
129
}
121
130
}
0 commit comments