@@ -22,7 +22,9 @@ class LambdaHandlerTest: XCTestCase {
2222
2323 func testBootstrapSimpleNoInit( ) {
2424 let server = MockLambdaServer ( behavior: Behavior ( ) )
25- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
25+ var port : Int ?
26+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
27+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
2628 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
2729
2830 struct TestBootstrapHandler : SimpleLambdaHandler {
@@ -32,14 +34,16 @@ class LambdaHandlerTest: XCTestCase {
3234 }
3335
3436 let maxTimes = Int . random ( in: 10 ... 20 )
35- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
37+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
3638 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
3739 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
3840 }
3941
4042 func testBootstrapSimpleInit( ) {
4143 let server = MockLambdaServer ( behavior: Behavior ( ) )
42- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
44+ var port : Int ?
45+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
46+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
4347 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
4448
4549 struct TestBootstrapHandler : SimpleLambdaHandler {
@@ -56,7 +60,7 @@ class LambdaHandlerTest: XCTestCase {
5660 }
5761
5862 let maxTimes = Int . random ( in: 10 ... 20 )
59- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
63+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
6064 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
6165 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
6266 }
@@ -65,7 +69,9 @@ class LambdaHandlerTest: XCTestCase {
6569
6670 func testBootstrapSuccess( ) {
6771 let server = MockLambdaServer ( behavior: Behavior ( ) )
68- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
72+ var port : Int ?
73+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
74+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
6975 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
7076
7177 struct TestBootstrapHandler : LambdaHandler {
@@ -83,14 +89,16 @@ class LambdaHandlerTest: XCTestCase {
8389 }
8490
8591 let maxTimes = Int . random ( in: 10 ... 20 )
86- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
92+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
8793 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
8894 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
8995 }
9096
9197 func testBootstrapFailure( ) {
9298 let server = MockLambdaServer ( behavior: FailedBootstrapBehavior ( ) )
93- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
99+ var port : Int ?
100+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
101+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
94102 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
95103
96104 struct TestBootstrapHandler : LambdaHandler {
@@ -108,14 +116,16 @@ class LambdaHandlerTest: XCTestCase {
108116 }
109117
110118 let maxTimes = Int . random ( in: 10 ... 20 )
111- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
119+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
112120 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
113121 assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
114122 }
115123
116124 func testHandlerSuccess( ) {
117125 let server = MockLambdaServer ( behavior: Behavior ( ) )
118- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
126+ var port : Int ?
127+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
128+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
119129 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
120130
121131 struct Handler : SimpleLambdaHandler {
@@ -125,30 +135,34 @@ class LambdaHandlerTest: XCTestCase {
125135 }
126136
127137 let maxTimes = Int . random ( in: 1 ... 10 )
128- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
138+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
129139 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
130140 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
131141 }
132142
133143 func testVoidHandlerSuccess( ) {
134144 let server = MockLambdaServer ( behavior: Behavior ( result: . success( nil ) ) )
135- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
145+ var port : Int ?
146+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
147+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
136148 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
137149
138150 struct Handler : SimpleLambdaHandler {
139151 func handle( _ event: String , context: LambdaContext ) async throws { }
140152 }
141153
142154 let maxTimes = Int . random ( in: 1 ... 10 )
143- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
155+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
144156
145157 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
146158 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
147159 }
148160
149161 func testHandlerFailure( ) {
150162 let server = MockLambdaServer ( behavior: Behavior ( result: . failure( TestError ( " boom " ) ) ) )
151- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
163+ var port : Int ?
164+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
165+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
152166 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
153167
154168 struct Handler : SimpleLambdaHandler {
@@ -158,7 +172,7 @@ class LambdaHandlerTest: XCTestCase {
158172 }
159173
160174 let maxTimes = Int . random ( in: 1 ... 10 )
161- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
175+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
162176 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
163177 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
164178 }
@@ -167,7 +181,9 @@ class LambdaHandlerTest: XCTestCase {
167181
168182 func testEventLoopSuccess( ) {
169183 let server = MockLambdaServer ( behavior: Behavior ( ) )
170- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
184+ var port : Int ?
185+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
186+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
171187 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
172188
173189 struct Handler : EventLoopLambdaHandler {
@@ -181,14 +197,16 @@ class LambdaHandlerTest: XCTestCase {
181197 }
182198
183199 let maxTimes = Int . random ( in: 1 ... 10 )
184- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
200+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
185201 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
186202 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
187203 }
188204
189205 func testVoidEventLoopSuccess( ) {
190206 let server = MockLambdaServer ( behavior: Behavior ( result: . success( nil ) ) )
191- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
207+ var port : Int ?
208+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
209+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
192210 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
193211
194212 struct Handler : EventLoopLambdaHandler {
@@ -202,14 +220,16 @@ class LambdaHandlerTest: XCTestCase {
202220 }
203221
204222 let maxTimes = Int . random ( in: 1 ... 10 )
205- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
223+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
206224 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
207225 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
208226 }
209227
210228 func testEventLoopFailure( ) {
211229 let server = MockLambdaServer ( behavior: Behavior ( result: . failure( TestError ( " boom " ) ) ) )
212- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
230+ var port : Int ?
231+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
232+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
213233 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
214234
215235 struct Handler : EventLoopLambdaHandler {
@@ -223,14 +243,16 @@ class LambdaHandlerTest: XCTestCase {
223243 }
224244
225245 let maxTimes = Int . random ( in: 1 ... 10 )
226- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
246+ let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
227247 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
228248 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
229249 }
230250
231251 func testEventLoopBootstrapFailure( ) {
232252 let server = MockLambdaServer ( behavior: FailedBootstrapBehavior ( ) )
233- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
253+ var port : Int ?
254+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
255+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
234256 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
235257
236258 struct Handler : EventLoopLambdaHandler {
@@ -244,7 +266,8 @@ class LambdaHandlerTest: XCTestCase {
244266 }
245267 }
246268
247- let result = Lambda . run ( configuration: . init( ) , handlerType: Handler . self)
269+ let configuration = LambdaConfiguration ( runtimeEngine: . init( address: " 127.0.0.1: \( port) " ) )
270+ let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
248271 assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
249272 }
250273}
0 commit comments