@@ -128,30 +128,30 @@ class LambdaTest: XCTestCase {
128
128
assertLambdaLifecycleResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
129
129
}
130
130
131
- #if false
132
- func testStartStop( ) {
131
+ func testStartStopInDebugMode( ) {
133
132
let server = MockLambdaServer ( behavior: Behavior ( ) )
134
133
XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
135
134
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
136
135
137
136
let signal = Signal . ALRM
138
137
let maxTimes = 1000
139
138
let configuration = Lambda . Configuration ( lifecycle: . init( maxTimes: maxTimes, stopSignal: signal) )
140
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: System . coreCount)
141
- defer { XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) ) }
142
139
143
- let future = Lambda . runAsync ( eventLoopGroup: eventLoopGroup, configuration: configuration, factory: { $0. makeSucceededFuture ( EchoHandler ( ) ) } )
144
140
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.
145
143
usleep ( 100_000 )
146
144
kill ( getpid ( ) , signal. rawValue)
147
145
}
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 " )
151
150
}
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) " )
153
154
}
154
- #endif
155
155
156
156
func testTimeout( ) {
157
157
let timeout : Int64 = 100
0 commit comments