@@ -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,19 @@ 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 (
38+ lifecycle: . init( maxTimes: maxTimes) ,
39+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
40+ )
3641 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
3742 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
3843 }
3944
4045 func testBootstrapSimpleInit( ) {
4146 let server = MockLambdaServer ( behavior: Behavior ( ) )
42- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
47+ var port : Int ?
48+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
49+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
4350 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
4451
4552 struct TestBootstrapHandler : SimpleLambdaHandler {
@@ -56,7 +63,10 @@ class LambdaHandlerTest: XCTestCase {
5663 }
5764
5865 let maxTimes = Int . random ( in: 10 ... 20 )
59- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
66+ let configuration = LambdaConfiguration (
67+ lifecycle: . init( maxTimes: maxTimes) ,
68+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
69+ )
6070 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
6171 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
6272 }
@@ -65,7 +75,9 @@ class LambdaHandlerTest: XCTestCase {
6575
6676 func testBootstrapSuccess( ) {
6777 let server = MockLambdaServer ( behavior: Behavior ( ) )
68- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
78+ var port : Int ?
79+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
80+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
6981 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
7082
7183 struct TestBootstrapHandler : LambdaHandler {
@@ -83,14 +95,19 @@ class LambdaHandlerTest: XCTestCase {
8395 }
8496
8597 let maxTimes = Int . random ( in: 10 ... 20 )
86- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
98+ let configuration = LambdaConfiguration (
99+ lifecycle: . init( maxTimes: maxTimes) ,
100+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
101+ )
87102 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
88103 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
89104 }
90105
91106 func testBootstrapFailure( ) {
92107 let server = MockLambdaServer ( behavior: FailedBootstrapBehavior ( ) )
93- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
108+ var port : Int ?
109+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
110+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
94111 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
95112
96113 struct TestBootstrapHandler : LambdaHandler {
@@ -108,14 +125,19 @@ class LambdaHandlerTest: XCTestCase {
108125 }
109126
110127 let maxTimes = Int . random ( in: 10 ... 20 )
111- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
128+ let configuration = LambdaConfiguration (
129+ lifecycle: . init( maxTimes: maxTimes) ,
130+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
131+ )
112132 let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
113133 assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
114134 }
115135
116136 func testHandlerSuccess( ) {
117137 let server = MockLambdaServer ( behavior: Behavior ( ) )
118- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
138+ var port : Int ?
139+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
140+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
119141 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
120142
121143 struct Handler : SimpleLambdaHandler {
@@ -125,30 +147,40 @@ class LambdaHandlerTest: XCTestCase {
125147 }
126148
127149 let maxTimes = Int . random ( in: 1 ... 10 )
128- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
150+ let configuration = LambdaConfiguration (
151+ lifecycle: . init( maxTimes: maxTimes) ,
152+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
153+ )
129154 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
130155 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
131156 }
132157
133158 func testVoidHandlerSuccess( ) {
134159 let server = MockLambdaServer ( behavior: Behavior ( result: . success( nil ) ) )
135- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
160+ var port : Int ?
161+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
162+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
136163 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
137164
138165 struct Handler : SimpleLambdaHandler {
139166 func handle( _ event: String , context: LambdaContext ) async throws { }
140167 }
141168
142169 let maxTimes = Int . random ( in: 1 ... 10 )
143- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
170+ let configuration = LambdaConfiguration (
171+ lifecycle: . init( maxTimes: maxTimes) ,
172+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
173+ )
144174
145175 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
146176 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
147177 }
148178
149179 func testHandlerFailure( ) {
150180 let server = MockLambdaServer ( behavior: Behavior ( result: . failure( TestError ( " boom " ) ) ) )
151- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
181+ var port : Int ?
182+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
183+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
152184 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
153185
154186 struct Handler : SimpleLambdaHandler {
@@ -158,7 +190,10 @@ class LambdaHandlerTest: XCTestCase {
158190 }
159191
160192 let maxTimes = Int . random ( in: 1 ... 10 )
161- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
193+ let configuration = LambdaConfiguration (
194+ lifecycle: . init( maxTimes: maxTimes) ,
195+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
196+ )
162197 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
163198 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
164199 }
@@ -167,7 +202,9 @@ class LambdaHandlerTest: XCTestCase {
167202
168203 func testEventLoopSuccess( ) {
169204 let server = MockLambdaServer ( behavior: Behavior ( ) )
170- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
205+ var port : Int ?
206+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
207+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
171208 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
172209
173210 struct Handler : EventLoopLambdaHandler {
@@ -181,14 +218,19 @@ class LambdaHandlerTest: XCTestCase {
181218 }
182219
183220 let maxTimes = Int . random ( in: 1 ... 10 )
184- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
221+ let configuration = LambdaConfiguration (
222+ lifecycle: . init( maxTimes: maxTimes) ,
223+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
224+ )
185225 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
186226 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
187227 }
188228
189229 func testVoidEventLoopSuccess( ) {
190230 let server = MockLambdaServer ( behavior: Behavior ( result: . success( nil ) ) )
191- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
231+ var port : Int ?
232+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
233+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
192234 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
193235
194236 struct Handler : EventLoopLambdaHandler {
@@ -202,14 +244,19 @@ class LambdaHandlerTest: XCTestCase {
202244 }
203245
204246 let maxTimes = Int . random ( in: 1 ... 10 )
205- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
247+ let configuration = LambdaConfiguration (
248+ lifecycle: . init( maxTimes: maxTimes) ,
249+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
250+ )
206251 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
207252 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
208253 }
209254
210255 func testEventLoopFailure( ) {
211256 let server = MockLambdaServer ( behavior: Behavior ( result: . failure( TestError ( " boom " ) ) ) )
212- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
257+ var port : Int ?
258+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
259+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
213260 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
214261
215262 struct Handler : EventLoopLambdaHandler {
@@ -223,14 +270,19 @@ class LambdaHandlerTest: XCTestCase {
223270 }
224271
225272 let maxTimes = Int . random ( in: 1 ... 10 )
226- let configuration = LambdaConfiguration ( lifecycle: . init( maxTimes: maxTimes) )
273+ let configuration = LambdaConfiguration (
274+ lifecycle: . init( maxTimes: maxTimes) ,
275+ runtimeEngine: . init( address: " 127.0.0.1: \( port) " )
276+ )
227277 let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
228278 assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
229279 }
230280
231281 func testEventLoopBootstrapFailure( ) {
232282 let server = MockLambdaServer ( behavior: FailedBootstrapBehavior ( ) )
233- XCTAssertNoThrow ( try server. start ( ) . wait ( ) )
283+ var port : Int ?
284+ XCTAssertNoThrow ( port = try server. start ( ) . wait ( ) )
285+ guard let port else { return XCTFail ( " Expected the server to have started " ) }
234286 defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
235287
236288 struct Handler : EventLoopLambdaHandler {
@@ -244,7 +296,8 @@ class LambdaHandlerTest: XCTestCase {
244296 }
245297 }
246298
247- let result = Lambda . run ( configuration: . init( ) , handlerType: Handler . self)
299+ let configuration = LambdaConfiguration ( runtimeEngine: . init( address: " 127.0.0.1: \( port) " ) )
300+ let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
248301 assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
249302 }
250303}
0 commit comments