diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 35b46aa3..baf78508 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -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} ] diff --git a/Package.swift b/Package.swift index 69f5ff36..d26d2042 100644 --- a/Package.swift +++ b/Package.swift @@ -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: [ diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift index 9eed4389..a23ef1cf 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift @@ -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)") diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 86274836..c058bf3d 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -76,7 +76,9 @@ public final class LambdaRuntime: @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: @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 } } }