File tree 2 files changed +22
-7
lines changed
Sources/AWSLambdaRuntimeCore
Tests/AWSLambdaRuntimeCoreTests
2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,11 @@ extension Lambda {
27
27
private let configuration : Configuration
28
28
private let factory : HandlerFactory
29
29
30
- private var state = State . idle
30
+ private var state = State . idle {
31
+ willSet {
32
+ precondition ( newValue. order > state. order, " invalid state \( newValue) after \( state. order) " )
33
+ }
34
+ }
31
35
32
36
/// Create a new `Lifecycle`.
33
37
///
@@ -62,8 +66,12 @@ extension Lambda {
62
66
63
67
/// Start the `Lifecycle`.
64
68
///
65
- /// - Returns: An `EventLoopFuture` that is fulfilled after the Lambda hander has been created and initiliazed, and a first run has been schduled.
69
+ /// - Returns: An `EventLoopFuture` that is fulfilled after the Lambda hander has been created and initiliazed, and a first run has been scheduled.
70
+ ///
71
+ /// - note: This method must be called on the `EventLoop` the `Lifecycle` has been initialized with.
66
72
public func start( ) -> EventLoopFuture < Void > {
73
+ assert ( self . eventLoop. inEventLoop, " Start must be called on the `EventLoop` the `Lifecycle` has been initialized with. " )
74
+
67
75
logger. info ( " lambda lifecycle starting with \( self . configuration) " )
68
76
self . state = . initializing
69
77
// triggered when the Lambda has finished its last run
Original file line number Diff line number Diff line change @@ -145,12 +145,19 @@ class LambdaTest: XCTestCase {
145
145
}
146
146
let result = Lambda . run ( configuration: configuration, factory: { $0. makeSucceededFuture ( EchoHandler ( ) ) } )
147
147
148
- guard case . success( let invocationCount) = result else {
149
- return XCTFail ( " expected to have not failed " )
148
+ switch result {
149
+ case . success( let invocationCount) :
150
+ // this is an allowed outcome. the lambda was cancelled while it was processing a task.
151
+ // therefore: it was shut down before asking for a new invocation
152
+ XCTAssertGreaterThan ( invocationCount, 0 , " should have stopped before any request made " )
153
+ XCTAssertLessThan ( invocationCount, maxTimes, " should have stopped before \( maxTimes) " )
154
+ case . failure( HTTPClient . Errors. cancelled) :
155
+ // this is an allowed outcome. while the lambda was asking for a new invocation it was
156
+ // cancelled. for this reason the get new invocation request failed with .cancelled.
157
+ break
158
+ case . failure( let error) :
159
+ XCTFail ( " Unexpected error: \( error) " )
150
160
}
151
-
152
- XCTAssertGreaterThan ( invocationCount, 0 , " should have stopped before any request made " )
153
- XCTAssertLessThan ( invocationCount, maxTimes, " should have stopped before \( maxTimes) " )
154
161
}
155
162
156
163
func testTimeout( ) {
You can’t perform that action at this time.
0 commit comments