@@ -44,26 +44,32 @@ struct BreezeLambdaWebHookServiceTests {
4444 @Test ( " Service creates HTTP client with correct timeout configuration " )
4545 func serviceCreatesHTTPClientWithCorrectConfig( ) async throws {
4646 try await testGracefulShutdown { gracefulShutdownTestTrigger in
47+ let ( gracefulStream, continuation) = AsyncStream< Void> . makeStream( )
4748 try await withThrowingTaskGroup ( of: Void . self) { group in
4849 let logger = Logger ( label: " test " )
4950 let config = BreezeHTTPClientConfig ( timeout: . seconds( 30 ) , logger: logger)
5051 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 {
5458 try await sut. run ( )
59+ print ( " BreezeLambdaAPIService started successfully " )
60+ } onGracefulShutdown: {
61+ logger. info ( " On Graceful Shutdown " )
62+ continuation. yield ( )
63+ continuation. finish ( )
5564 }
56- } onCancelOrGracefulShutdown: {
57- gracefulShutdownTestTrigger. triggerGracefulShutdown ( )
58- logger. info ( " On Graceful Shutdown " )
5965 }
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+ }
6773 }
6874 }
6975 }
@@ -86,36 +92,39 @@ struct BreezeLambdaWebHookServiceTests {
8692 @Test ( " Handler delegates to specific handler implementation " )
8793 func handlerDelegatesToImplementation( ) async throws {
8894 try await testGracefulShutdown { gracefulShutdownTestTrigger in
95+ let ( gracefulStream, continuation) = AsyncStream< Void> . makeStream( )
8996 try await withThrowingTaskGroup ( of: Void . self) { group in
90-
9197 let logger = Logger ( label: " test " )
9298 let config = BreezeHTTPClientConfig ( timeout: . seconds( 30 ) , logger: logger)
9399 let sut = BreezeLambdaWebHookService < MockHandler > ( config: config)
94-
100+ group. addTask {
101+ try await Task . sleep ( nanoseconds: 1_000_000_000 )
102+ gracefulShutdownTestTrigger. triggerGracefulShutdown ( )
103+ }
95104 group. addTask {
96105 try await withGracefulShutdownHandler {
97106 try await sut. run ( )
107+ print ( " BreezeLambdaAPIService started successfully " )
98108 } onGracefulShutdown: {
99109 logger. info ( " On Graceful Shutdown " )
110+ continuation. yield ( )
111+ continuation. finish ( )
100112 }
101113 }
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 ( )
105127 }
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 ( )
119128 }
120129 }
121130 }
0 commit comments