@@ -42,10 +42,10 @@ struct LambdaRuntimeClientTests {
42
42
. success( ( self . requestId, self . event) )
43
43
}
44
44
45
- func processResponse( requestId: String , response: String ? ) -> Result < Void , ProcessResponseError > {
45
+ func processResponse( requestId: String , response: String ? ) -> Result < String ? , ProcessResponseError > {
46
46
#expect( self . requestId == requestId)
47
47
#expect( self . event == response)
48
- return . success( ( ) )
48
+ return . success( nil )
49
49
}
50
50
51
51
func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
@@ -102,9 +102,9 @@ struct LambdaRuntimeClientTests {
102
102
. success( ( self . requestId, self . event) )
103
103
}
104
104
105
- func processResponse( requestId: String , response: String ? ) -> Result < Void , ProcessResponseError > {
105
+ func processResponse( requestId: String , response: String ? ) -> Result < String ? , ProcessResponseError > {
106
106
#expect( self . requestId == requestId)
107
- return . success( ( ) )
107
+ return . success( nil )
108
108
}
109
109
110
110
mutating func captureHeaders( _ headers: HTTPHeaders ) {
@@ -197,10 +197,10 @@ struct LambdaRuntimeClientTests {
197
197
. success( ( self . requestId, self . event) )
198
198
}
199
199
200
- func processResponse( requestId: String , response: String ? ) -> Result < Void , ProcessResponseError > {
200
+ func processResponse( requestId: String , response: String ? ) -> Result < String ? , ProcessResponseError > {
201
201
#expect( self . requestId == requestId)
202
202
#expect( self . event == response)
203
- return . success( ( ) )
203
+ return . success( nil )
204
204
}
205
205
206
206
func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
@@ -239,31 +239,56 @@ struct LambdaRuntimeClientTests {
239
239
}
240
240
}
241
241
242
- @Test ( " Server closing the connection when waiting for next invocation throws an error " )
243
- func testChannelCloseFutureWithWaitingForNextInvocation( ) async throws {
244
- struct DisconnectBehavior : LambdaServerBehavior {
245
- func getInvocation( ) -> GetInvocationResult {
246
- // Return "disconnect" to trigger server closing the connection
247
- . success( ( " disconnect " , " 0 " ) )
248
- }
242
+ struct DisconnectAfterSendingResponseBehavior : LambdaServerBehavior {
243
+ func getInvocation( ) -> GetInvocationResult {
244
+ . success( ( UUID ( ) . uuidString, " hello " ) )
245
+ }
249
246
250
- func processResponse( requestId: String , response: String ? ) -> Result < Void , ProcessResponseError > {
251
- Issue . record ( " should not process response " )
252
- return . failure( . internalServerError)
253
- }
247
+ func processResponse( requestId: String , response: String ? ) -> Result < String ? , ProcessResponseError > {
248
+ // Return "disconnect" to trigger server closing the connection
249
+ // after having accepted a response
250
+ . success( " delayed-disconnect " )
251
+ }
254
252
255
- func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
256
- Issue . record ( " should not report error " )
257
- return . failure( . internalServerError)
258
- }
253
+ func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
254
+ Issue . record ( " should not report error " )
255
+ return . failure( . internalServerError)
256
+ }
259
257
260
- func processInitError( error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
261
- Issue . record ( " should not report init error " )
262
- return . failure( . internalServerError)
263
- }
258
+ func processInitError( error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
259
+ Issue . record ( " should not report init error " )
260
+ return . failure( . internalServerError)
261
+ }
262
+ }
263
+
264
+ struct DisconnectBehavior : LambdaServerBehavior {
265
+ func getInvocation( ) -> GetInvocationResult {
266
+ // Return "disconnect" to trigger server closing the connection
267
+ . success( ( " disconnect " , " 0 " ) )
264
268
}
265
269
266
- try await withMockServer ( behaviour: DisconnectBehavior ( ) ) { port in
270
+ func processResponse( requestId: String , response: String ? ) -> Result < String ? , ProcessResponseError > {
271
+ Issue . record ( " should not process response " )
272
+ return . failure( . internalServerError)
273
+ }
274
+
275
+ func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
276
+ Issue . record ( " should not report error " )
277
+ return . failure( . internalServerError)
278
+ }
279
+
280
+ func processInitError( error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
281
+ Issue . record ( " should not report init error " )
282
+ return . failure( . internalServerError)
283
+ }
284
+ }
285
+
286
+ @Test (
287
+ " Server closing the connection when waiting for next invocation throws an error " ,
288
+ arguments: [ DisconnectAfterSendingResponseBehavior ( ) , DisconnectBehavior ( ) ] as [ any LambdaServerBehavior ]
289
+ )
290
+ func testChannelCloseFutureWithWaitingForNextInvocation( behavior: LambdaServerBehavior ) async throws {
291
+ try await withMockServer ( behaviour: behavior) { port in
267
292
let configuration = LambdaRuntimeClient . Configuration ( ip: " 127.0.0.1 " , port: port)
268
293
269
294
try await LambdaRuntimeClient . withRuntimeClient (
@@ -273,7 +298,12 @@ struct LambdaRuntimeClientTests {
273
298
) { runtimeClient in
274
299
do {
275
300
// This should fail when server closes connection
301
+ let ( _, writer) = try await runtimeClient. nextInvocation ( )
302
+ let response = ByteBuffer ( string: " hello " )
303
+ try await writer. writeAndFinish ( response)
304
+
276
305
let _ = try await runtimeClient. nextInvocation ( )
306
+
277
307
Issue . record ( " Expected connection error but got successful invocation " )
278
308
279
309
} catch let error as LambdaRuntimeError {
0 commit comments