@@ -22,7 +22,9 @@ class LambdaHandlerTest: XCTestCase {
22
22
23
23
func testBootstrapSimpleNoInit( ) {
24
24
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 " ) }
26
28
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
27
29
28
30
struct TestBootstrapHandler : SimpleLambdaHandler {
@@ -32,14 +34,19 @@ class LambdaHandlerTest: XCTestCase {
32
34
}
33
35
34
36
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
+ )
36
41
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
37
42
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
38
43
}
39
44
40
45
func testBootstrapSimpleInit( ) {
41
46
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 " ) }
43
50
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
44
51
45
52
struct TestBootstrapHandler : SimpleLambdaHandler {
@@ -56,7 +63,10 @@ class LambdaHandlerTest: XCTestCase {
56
63
}
57
64
58
65
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
+ )
60
70
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
61
71
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
62
72
}
@@ -65,7 +75,9 @@ class LambdaHandlerTest: XCTestCase {
65
75
66
76
func testBootstrapSuccess( ) {
67
77
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 " ) }
69
81
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
70
82
71
83
struct TestBootstrapHandler : LambdaHandler {
@@ -83,14 +95,19 @@ class LambdaHandlerTest: XCTestCase {
83
95
}
84
96
85
97
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
+ )
87
102
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
88
103
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
89
104
}
90
105
91
106
func testBootstrapFailure( ) {
92
107
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 " ) }
94
111
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
95
112
96
113
struct TestBootstrapHandler : LambdaHandler {
@@ -108,14 +125,19 @@ class LambdaHandlerTest: XCTestCase {
108
125
}
109
126
110
127
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
+ )
112
132
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
113
133
assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
114
134
}
115
135
116
136
func testHandlerSuccess( ) {
117
137
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 " ) }
119
141
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
120
142
121
143
struct Handler : SimpleLambdaHandler {
@@ -125,30 +147,40 @@ class LambdaHandlerTest: XCTestCase {
125
147
}
126
148
127
149
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
+ )
129
154
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
130
155
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
131
156
}
132
157
133
158
func testVoidHandlerSuccess( ) {
134
159
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 " ) }
136
163
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
137
164
138
165
struct Handler : SimpleLambdaHandler {
139
166
func handle( _ event: String , context: LambdaContext ) async throws { }
140
167
}
141
168
142
169
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
+ )
144
174
145
175
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
146
176
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
147
177
}
148
178
149
179
func testHandlerFailure( ) {
150
180
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 " ) }
152
184
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
153
185
154
186
struct Handler : SimpleLambdaHandler {
@@ -158,7 +190,10 @@ class LambdaHandlerTest: XCTestCase {
158
190
}
159
191
160
192
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
+ )
162
197
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
163
198
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
164
199
}
@@ -167,7 +202,9 @@ class LambdaHandlerTest: XCTestCase {
167
202
168
203
func testEventLoopSuccess( ) {
169
204
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 " ) }
171
208
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
172
209
173
210
struct Handler : EventLoopLambdaHandler {
@@ -181,14 +218,19 @@ class LambdaHandlerTest: XCTestCase {
181
218
}
182
219
183
220
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
+ )
185
225
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
186
226
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
187
227
}
188
228
189
229
func testVoidEventLoopSuccess( ) {
190
230
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 " ) }
192
234
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
193
235
194
236
struct Handler : EventLoopLambdaHandler {
@@ -202,14 +244,19 @@ class LambdaHandlerTest: XCTestCase {
202
244
}
203
245
204
246
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
+ )
206
251
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
207
252
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
208
253
}
209
254
210
255
func testEventLoopFailure( ) {
211
256
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 " ) }
213
260
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
214
261
215
262
struct Handler : EventLoopLambdaHandler {
@@ -223,14 +270,19 @@ class LambdaHandlerTest: XCTestCase {
223
270
}
224
271
225
272
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
+ )
227
277
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
228
278
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
229
279
}
230
280
231
281
func testEventLoopBootstrapFailure( ) {
232
282
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 " ) }
234
286
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
235
287
236
288
struct Handler : EventLoopLambdaHandler {
@@ -244,7 +296,8 @@ class LambdaHandlerTest: XCTestCase {
244
296
}
245
297
}
246
298
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)
248
301
assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
249
302
}
250
303
}
0 commit comments