Update local server for Swift 6 compliance (#428)

* Update local server to Swift 6

* fix compilation error for local server in release mode

* [CI] fix error for integration plugin test
This commit is contained in:
Sébastien Stormacq
2024-11-16 10:22:01 +01:00
committed by GitHub
parent 8724c47211
commit 21e224ea8d
4 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -114,7 +114,7 @@ jobs:
pushd Examples/${EXAMPLE}
# package the example (docker and swift toolchain are installed on the GH runner)
echo yes | swift package archive --allow-network-connections docker
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker
# did the plugin generated a Linux binary?
[ -f ${OUTPUT_FILE} ]
+1 -1
View File
@@ -23,7 +23,7 @@ let package = Package(
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.72.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.76.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
],
targets: [
@@ -12,8 +12,6 @@
//
//===----------------------------------------------------------------------===//
// commented out as long as we have a fix for Swift 6 language mode CI
#if DEBUG
import Dispatch
import Logging
@@ -133,6 +131,10 @@ private enum LocalLambda {
}
func processRequest(context: ChannelHandlerContext, request: (head: HTTPRequestHead, body: ByteBuffer?)) {
let eventLoop = context.eventLoop
let loopBoundContext = NIOLoopBound(context, eventLoop: eventLoop)
switch (request.head.method, request.head.uri) {
// this endpoint is called by the client invoking the lambda
case (.POST, let url) where url.hasSuffix(self.invocationEndpoint):
@@ -142,6 +144,7 @@ private enum LocalLambda {
let requestID = "\(DispatchTime.now().uptimeNanoseconds)" // FIXME:
let promise = context.eventLoop.makePromise(of: Response.self)
promise.futureResult.whenComplete { result in
let context = loopBoundContext.value
switch result {
case .failure(let error):
self.logger.error("invocation error: \(error)")
@@ -178,6 +181,7 @@ private enum LocalLambda {
// create a promise that we can fullfill when we get a new task
let promise = context.eventLoop.makePromise(of: Invocation.self)
promise.futureResult.whenComplete { result in
let context = loopBoundContext.value
switch result {
case .failure(let error):
self.logger.error("invocation error: \(error)")
@@ -76,7 +76,9 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
} else {
// we're not running on Lambda, let's start a local server for testing
#if DEBUG
// we're not running on Lambda and we're compiled in DEBUG mode,
// let's start a local server for testing
try await Lambda.withLocalServer(invocationEndpoint: Lambda.env("LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT"))
{
@@ -92,6 +94,10 @@ public final class LambdaRuntime<Handler>: @unchecked Sendable where Handler: St
)
}
}
#else
// in release mode, we can't start a local server because the local server code is not compiled.
throw LambdaRuntimeError(code: .missingLambdaRuntimeAPIEnvironmentVariable)
#endif
}
}
}