Skip to content

Commit a0b1d57

Browse files
committed
give more time to the server to close the connection
1 parent 156e6c7 commit a0b1d57

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Tests/AWSLambdaRuntimeTests/LambdaRuntimeClientTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ struct LambdaRuntimeClientTests {
245245
}
246246

247247
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
250250
.success("delayed-disconnect")
251251
}
252252

@@ -261,15 +261,13 @@ struct LambdaRuntimeClientTests {
261261
}
262262
}
263263

264-
struct DisconnectBehavior: LambdaServerBehavior {
264+
struct DisconnectBehavior: LambdaServerBehavior {
265265
func getInvocation() -> GetInvocationResult {
266-
// Return "disconnect" to trigger server closing the connection
267266
.success(("disconnect", "0"))
268267
}
269268

270269
func processResponse(requestId: String, response: String?) -> Result<String?, ProcessResponseError> {
271-
Issue.record("should not process response")
272-
return .failure(.internalServerError)
270+
.success(nil)
273271
}
274272

275273
func processError(requestId: String, error: ErrorResponse) -> Result<Void, ProcessErrorError> {
@@ -285,7 +283,7 @@ struct LambdaRuntimeClientTests {
285283

286284
@Test(
287285
"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]
289287
)
290288
func testChannelCloseFutureWithWaitingForNextInvocation(behavior: LambdaServerBehavior) async throws {
291289
try await withMockServer(behaviour: behavior) { port in
@@ -297,12 +295,14 @@ struct LambdaRuntimeClientTests {
297295
logger: self.logger
298296
) { runtimeClient in
299297
do {
300-
// This should fail when server closes connection
301298
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"))
304300

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+
}
306306

307307
Issue.record("Expected connection error but got successful invocation")
308308

0 commit comments

Comments
 (0)