Skip to content

Commit 4cc896e

Browse files
committed
Fix test
1 parent 7b87c3d commit 4cc896e

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ let package = Package(
1818
.library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]),
1919
],
2020
dependencies: [
21-
.package(url: "https://github.com/weissi/swift-nio.git", .branch("jw-single-threaded-nio")),
22-
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
23-
.package(url: "https://github.com/swift-server/swift-backtrace.git", from: "1.1.0"),
21+
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.17.0")),
22+
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.0.0")),
23+
.package(url: "https://github.com/swift-server/swift-backtrace.git", .upToNextMajor(from: "1.1.0")),
2424
],
2525
targets: [
2626
.target(name: "AWSLambdaRuntime", dependencies: [

Sources/AWSLambdaRuntimeCore/Lambda.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public enum Lambda {
8181
internal static func run(configuration: Configuration = .init(), factory: @escaping (EventLoop) throws -> Handler) -> Result<Int, Error> {
8282
self.run(configuration: configuration, factory: { eventloop -> EventLoopFuture<Handler> in
8383
let promise = eventloop.makePromise(of: Handler.self)
84+
// if we have a callback based handler factory, we offload the creation of the handler
85+
// onto the default offload queue, to ensure that the eventloop is never blocked.
8486
Lambda.defaultOffloadQueue.async {
8587
do {
8688
promise.succeed(try factory(eventloop))

Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,30 @@ class LambdaTest: XCTestCase {
128128
assertLambdaLifecycleResult(result, shouldFailWithError: TestError("kaboom"))
129129
}
130130

131-
#if false
132-
func testStartStop() {
131+
func testStartStopInDebugMode() {
133132
let server = MockLambdaServer(behavior: Behavior())
134133
XCTAssertNoThrow(try server.start().wait())
135134
defer { XCTAssertNoThrow(try server.stop().wait()) }
136135

137136
let signal = Signal.ALRM
138137
let maxTimes = 1000
139138
let configuration = Lambda.Configuration(lifecycle: .init(maxTimes: maxTimes, stopSignal: signal))
140-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
141-
defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) }
142139

143-
let future = Lambda.runAsync(eventLoopGroup: eventLoopGroup, configuration: configuration, factory: { $0.makeSucceededFuture(EchoHandler()) })
144140
DispatchQueue(label: "test").async {
141+
// we need to schedule the signal before we start the long running `Lambda.run`, since
142+
// `Lambda.run` will block the main thread.
145143
usleep(100_000)
146144
kill(getpid(), signal.rawValue)
147145
}
148-
future.whenSuccess { result in
149-
XCTAssertGreaterThan(result, 0, "should have stopped before any request made")
150-
XCTAssertLessThan(result, maxTimes, "should have stopped before \(maxTimes)")
146+
let result = Lambda.run(configuration: configuration, factory: { $0.makeSucceededFuture(EchoHandler()) })
147+
148+
guard case .success(let invocationCount) = result else {
149+
return XCTFail("expected to have not failed")
151150
}
152-
XCTAssertNoThrow(try future.wait())
151+
152+
XCTAssertGreaterThan(invocationCount, 0, "should have stopped before any request made")
153+
XCTAssertLessThan(invocationCount, maxTimes, "should have stopped before \(maxTimes)")
153154
}
154-
#endif
155155

156156
func testTimeout() {
157157
let timeout: Int64 = 100

0 commit comments

Comments
 (0)