-
Notifications
You must be signed in to change notification settings - Fork 113
[core] Only one LambdaRuntime.run()
can be called at a time (fix #507)
#508
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
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
456569a
make LambdaRuntime a singleton without breaking the API
sebsto a63a639
fix license header
sebsto 40b6127
convert Mutex to NIOLockedValueBox
sebsto d474eba
Replace NIOLockedValueBox with Mutex
sebsto 46e76f3
revert replacing NIOLockedValueBox by Mutex
sebsto 299b9bc
remove typed throw (workaround for https://github.com/swiftlang/swift…
sebsto e3a3851
fix integration tests
sebsto 4ebf24f
Replace NIOLockedValueBox with Mutex
sebsto f3e65ac
Merge branch 'main' into sebsto/fix_507
sebsto 3aee427
use Atomic instead of Mutex.
sebsto e445f90
Merge branch 'sebsto/fix_507' of github.com:sebsto/swift-aws-lambda-r…
sebsto 0509eaa
revert `try` on `runtime.init()` in doc
sebsto aa6395f
revert unwanted change
sebsto 066ab76
revert unwanted change
sebsto e01b25d
swift-format
sebsto 23c4b64
Merge branch 'main' into sebsto/fix_507
sebsto 57e2396
Update Sources/AWSLambdaRuntime/LambdaRuntime.swift
sebsto 85c988d
Update Sources/AWSLambdaRuntime/LambdaRuntime.swift
sebsto ab80580
Update Sources/AWSLambdaRuntime/LambdaRuntimeError.swift
sebsto 10304ce
Update Sources/AWSLambdaRuntime/LambdaRuntimeError.swift
sebsto c1e68fc
Update Tests/AWSLambdaRuntimeTests/LambdaRuntimeTests.swift
sebsto 918492a
Update Tests/AWSLambdaRuntimeTests/LambdaRuntimeTests.swift
sebsto 6ada041
Update Tests/AWSLambdaRuntimeTests/LambdaRuntimeTests.swift
sebsto 06df831
add package visibility to Code
sebsto 50b9df8
swift format
sebsto fa0fd88
remove print statement
sebsto 4b2b32d
Merge branch 'main' into sebsto/fix_507
sebsto 6aeafbf
Merge branch 'main' into sebsto/fix_507
sebsto 9fb86a7
Merge branch 'sebsto/fix_507' of github.com:sebsto/swift-aws-lambda-r…
sebsto f7ad7c0
Merge branch 'main' into sebsto/fix_507
sebsto b60d6e5
apply swift format
sebsto fbdf503
make LambdaRuntimeError package to be inlinable
sebsto 6353d96
fix example dependencies
sebsto ee296b4
Merge branch 'main' into sebsto/fix_507
sebsto e00c1c4
improve logging when task is cancelled
sebsto b33b6ed
let the lambda runtime set the debug level
sebsto c5eb4ae
adjust test for task cancellation
sebsto 0b111cd
typos
sebsto ce23a65
Merge branch 'main' into sebsto/fix_507
sebsto acf3d7f
simplify check for single instance and single run() invocation
sebsto 9d2cab9
swift-format
sebsto 9737c8a
Merge branch 'main' into sebsto/fix_507
sebsto 7b50167
re-add the check on unique Handler and remove the @unchecked on Lambd…
sebsto b449a4d
make sure UnsafeTransferBox is reserved to internal usage
sebsto cf33d7b
use is instead of as? ... != nil
sebsto f209493
renamae handlerMutex to handlerStorage
sebsto 7ac5292
further rename handlerMutex
sebsto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftAWSLambdaRuntime open source project | ||
// | ||
// Copyright (c) 2025 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import Logging | ||
import NIOCore | ||
import Synchronization | ||
import Testing | ||
|
||
@testable import AWSLambdaRuntime | ||
|
||
@Suite("LambdaRuntimeTests") | ||
struct LambdaRuntimeTests { | ||
|
||
@Test("LambdaRuntime can only be run once") | ||
func testLambdaRuntimerunOnce() async throws { | ||
|
||
// First runtime | ||
let runtime1 = LambdaRuntime( | ||
handler: MockHandler(), | ||
eventLoop: Lambda.defaultEventLoop, | ||
logger: Logger(label: "LambdaRuntimeTests.Runtime1") | ||
) | ||
|
||
// Second runtime | ||
let runtime2 = LambdaRuntime( | ||
handler: MockHandler(), | ||
eventLoop: Lambda.defaultEventLoop, | ||
logger: Logger(label: "LambdaRuntimeTests.Runtime2") | ||
) | ||
|
||
try await withThrowingTaskGroup(of: Void.self) { taskGroup in | ||
// start the first runtime | ||
taskGroup.addTask { | ||
// ChannelError will be thrown when we cancel the task group | ||
await #expect(throws: ChannelError.self) { | ||
try await runtime1.run() | ||
} | ||
} | ||
|
||
// wait a small amount to ensure runtime1 task is started | ||
try await Task.sleep(for: .seconds(1)) | ||
|
||
// Running the second runtime should trigger LambdaRuntimeError | ||
await #expect(throws: LambdaRuntimeError.self) { | ||
try await runtime2.run() | ||
} | ||
|
||
// cancel runtime 1 / task 1 | ||
taskGroup.cancelAll() | ||
} | ||
|
||
// Running the second runtime should work now | ||
try await withThrowingTaskGroup(of: Void.self) { taskGroup in | ||
taskGroup.addTask { | ||
// ChannelError will be thrown when we cancel the task group | ||
await #expect(throws: ChannelError.self) { | ||
try await runtime2.run() | ||
} | ||
} | ||
|
||
// Set timeout and cancel the runtime 2 | ||
try await Task.sleep(for: .seconds(2)) | ||
taskGroup.cancelAll() | ||
} | ||
} | ||
} | ||
|
||
struct MockHandler: StreamingLambdaHandler { | ||
mutating func handle( | ||
_ event: NIOCore.ByteBuffer, | ||
responseWriter: some AWSLambdaRuntime.LambdaResponseStreamWriter, | ||
context: AWSLambdaRuntime.LambdaContext | ||
) async throws { | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.