Skip to content

Commit a5fb165

Browse files
authored
fix concurrency api usage (#282)
motivation: cleanup incorrect concurent code in test changes: use .get instead of .wait
1 parent dc64ce1 commit a5fb165

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Sources/AWSLambdaRuntimeCore/LambdaRunner.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,6 @@ extension Result {
158158
}
159159
}
160160
}
161+
162+
/// This is safe since lambda runtime synchronizes by dispatching all methods to a single `EventLoop`
163+
extension LambdaRunner: @unchecked Sendable {}

Tests/AWSLambdaRuntimeCoreTests/LambdaTest.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class LambdaTest: XCTestCase {
266266
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
267267
defer { XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully()) }
268268

269-
let server = try MockLambdaServer(behavior: Behavior()).start().wait()
269+
let server = try await MockLambdaServer(behavior: Behavior()).start().get()
270270
defer { XCTAssertNoThrow(try server.stop().wait()) }
271271

272272
let logger = Logger(label: "TestLogger")
@@ -278,17 +278,17 @@ class LambdaTest: XCTestCase {
278278
logger.info("hello")
279279
let runner = LambdaRunner(eventLoop: eventLoopGroup.next(), configuration: configuration)
280280

281-
try runner.run(
281+
try await runner.run(
282282
handler: CodableEventLoopLambdaHandler(
283283
handler: handler1,
284284
allocator: ByteBufferAllocator()
285285
),
286286
logger: logger
287-
).wait()
287+
).get()
288288

289-
try runner.initialize(handlerType: CodableEventLoopLambdaHandler<Handler>.self, logger: logger, terminator: LambdaTerminator()).flatMap { handler2 in
289+
try await runner.initialize(handlerType: CodableEventLoopLambdaHandler<Handler>.self, logger: logger, terminator: LambdaTerminator()).flatMap { handler2 in
290290
runner.run(handler: handler2, logger: logger)
291-
}.wait()
291+
}.get()
292292
}
293293

294294
try await task.value

docker/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# this file is not designed to be run directly
22
# instead, use the docker-compose.<os>.<swift> files
3-
# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.al2.55.yaml run test
3+
# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.al2.57.yaml run test
44
version: "3"
55

66
services:

0 commit comments

Comments
 (0)