Skip to content

Commit 04d9fc7

Browse files
committed
fix unit tests
1 parent a69ed54 commit 04d9fc7

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

Sources/AWSLambdaRuntime/Lambda.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public enum Lambda {
5252
let _ = try await futureConnectionClosed.get()
5353
}
5454

55+
logger.trace("Waiting for next invocation")
5556
let (invocation, writer) = try await runtimeClient.nextInvocation()
5657
logger[metadataKey: "aws-request-id"] = "\(invocation.metadata.requestID)"
5758

@@ -87,10 +88,13 @@ public enum Lambda {
8788
logger: logger
8889
)
8990
)
91+
logger.trace("Handler finished processing invocation")
9092
} catch {
93+
logger.trace("Handler failed processing invocation", metadata: ["Handler error": "\(error)"])
9194
try await writer.reportError(error)
9295
continue
9396
}
97+
logger.handler.metadata.removeValue(forKey: "aws-request-id")
9498
}
9599
} catch is CancellationError {
96100
// don't allow cancellation error to propagate further

Sources/AWSLambdaRuntime/LambdaRuntime+ServiceLifecycle.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,20 @@ import ServiceLifecycle
1717

1818
extension LambdaRuntime: Service {
1919
public func run() async throws {
20-
await cancelWhenGracefulShutdown {
20+
try await cancelWhenGracefulShutdown {
2121
do {
2222
try await self._run()
2323
} catch {
2424
// catch top level errors that have not been handled until now
2525
// this avoids the runtime to crash and generate a backtrace
2626
self.logger.error("LambdaRuntime.run() failed with error", metadata: ["error": "\(error)"])
27+
if let error = error as? LambdaRuntimeError,
28+
error.code != .connectionToControlPlaneLost
29+
{
30+
// if the error is a LambdaRuntimeError but not a connection error,
31+
// we rethrow it to preserve existing behaviour
32+
throw error
33+
}
2734
}
2835
}
2936
}

Sources/AWSLambdaRuntime/LambdaRuntime.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public final class LambdaRuntime<Handler>: Sendable where Handler: StreamingLamb
6565
// catch top level errors that have not been handled until now
6666
// this avoids the runtime to crash and generate a backtrace
6767
self.logger.error("LambdaRuntime.run() failed with error", metadata: ["error": "\(error)"])
68+
if let error = error as? LambdaRuntimeError,
69+
error.code != .connectionToControlPlaneLost
70+
{
71+
// if the error is a LambdaRuntimeError but not a connection error,
72+
// we rethrow it to preserve existing behaviour
73+
throw error
74+
}
6875
}
6976
}
7077
#endif

Sources/AWSLambdaRuntime/LambdaRuntimeClient.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
121121
} catch {
122122
result = .failure(error)
123123
}
124-
125124
await runtime.close()
126125

127-
//try? await runtime.close()
128126
return try result.get()
129127
}
130128

@@ -375,7 +373,7 @@ final actor LambdaRuntimeClient: LambdaRuntimeClientProtocol {
375373
// however, this happens when performance testing against the MockServer
376374
// shutdown this runtime.
377375
// The Lambda service will create a new runtime environment anyway
378-
runtimeClient.logger.trace("Connection to Lambda API. lost, exiting")
376+
runtimeClient.logger.trace("Connection to Lambda Service HTTP Server lost, exiting")
379377
runtimeClient.futureConnectionClosed = runtimeClient.eventLoop.makeFailedFuture(
380378
LambdaRuntimeError(code: .connectionToControlPlaneLost)
381379
)

0 commit comments

Comments
 (0)