Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update local server for Swift 6 compliance #428

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 6 additions & 2 deletions Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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)")
Expand Down Expand Up @@ -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)")
Expand Down
8 changes: 7 additions & 1 deletion Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{

Expand All @@ -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
}
}
}
Loading