@@ -245,8 +245,8 @@ struct LambdaRuntimeClientTests {
245
245
}
246
246
247
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
248
+ // Return "delayed- disconnect" to trigger server closing the connection
249
+ // after having accepted the first response
250
250
. success( " delayed-disconnect " )
251
251
}
252
252
@@ -261,15 +261,13 @@ struct LambdaRuntimeClientTests {
261
261
}
262
262
}
263
263
264
- struct DisconnectBehavior : LambdaServerBehavior {
264
+ struct DisconnectBehavior : LambdaServerBehavior {
265
265
func getInvocation( ) -> GetInvocationResult {
266
- // Return "disconnect" to trigger server closing the connection
267
266
. success( ( " disconnect " , " 0 " ) )
268
267
}
269
268
270
269
func processResponse( requestId: String , response: String ? ) -> Result < String ? , ProcessResponseError > {
271
- Issue . record ( " should not process response " )
272
- return . failure( . internalServerError)
270
+ . success( nil )
273
271
}
274
272
275
273
func processError( requestId: String , error: ErrorResponse ) -> Result < Void , ProcessErrorError > {
@@ -285,7 +283,7 @@ struct LambdaRuntimeClientTests {
285
283
286
284
@Test (
287
285
" Server closing the connection when waiting for next invocation throws an error " ,
288
- arguments: [ DisconnectAfterSendingResponseBehavior ( ) , DisconnectBehavior ( ) ] as [ any LambdaServerBehavior ]
286
+ arguments: [ DisconnectBehavior ( ) , DisconnectAfterSendingResponseBehavior ( ) ] as [ any LambdaServerBehavior ]
289
287
)
290
288
func testChannelCloseFutureWithWaitingForNextInvocation( behavior: LambdaServerBehavior ) async throws {
291
289
try await withMockServer ( behaviour: behavior) { port in
@@ -297,12 +295,14 @@ struct LambdaRuntimeClientTests {
297
295
logger: self . logger
298
296
) { runtimeClient in
299
297
do {
300
- // This should fail when server closes connection
301
298
let ( _, writer) = try await runtimeClient. nextInvocation ( )
302
- let response = ByteBuffer ( string: " hello " )
303
- try await writer. writeAndFinish ( response)
299
+ try await writer. writeAndFinish ( ByteBuffer ( string: " hello " ) )
304
300
305
- let _ = try await runtimeClient. nextInvocation ( )
301
+ // continue to simulate traffic until the server reports it has closed the connection
302
+ for i in 1 ... 100 {
303
+ let ( _, writer2) = try await runtimeClient. nextInvocation ( )
304
+ try await writer2. writeAndFinish ( ByteBuffer ( string: " hello " ) )
305
+ }
306
306
307
307
Issue . record ( " Expected connection error but got successful invocation " )
308
308
0 commit comments