@@ -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,16 @@ 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 ( lifecycle: . init( maxTimes: maxTimes) , runtimeEngine : . init ( address : " 127.0.0.1: \( port ) " ) )
36
38
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
37
39
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
38
40
}
39
41
40
42
func testBootstrapSimpleInit( ) {
41
43
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 " ) }
43
47
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
44
48
45
49
struct TestBootstrapHandler : SimpleLambdaHandler {
@@ -56,7 +60,7 @@ class LambdaHandlerTest: XCTestCase {
56
60
}
57
61
58
62
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 ) " ) )
60
64
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
61
65
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
62
66
}
@@ -65,7 +69,9 @@ class LambdaHandlerTest: XCTestCase {
65
69
66
70
func testBootstrapSuccess( ) {
67
71
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 " ) }
69
75
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
70
76
71
77
struct TestBootstrapHandler : LambdaHandler {
@@ -83,14 +89,16 @@ class LambdaHandlerTest: XCTestCase {
83
89
}
84
90
85
91
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 ) " ) )
87
93
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
88
94
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
89
95
}
90
96
91
97
func testBootstrapFailure( ) {
92
98
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 " ) }
94
102
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
95
103
96
104
struct TestBootstrapHandler : LambdaHandler {
@@ -108,14 +116,16 @@ class LambdaHandlerTest: XCTestCase {
108
116
}
109
117
110
118
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 ) " ) )
112
120
let result = Lambda . run ( configuration: configuration, handlerType: TestBootstrapHandler . self)
113
121
assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
114
122
}
115
123
116
124
func testHandlerSuccess( ) {
117
125
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 " ) }
119
129
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
120
130
121
131
struct Handler : SimpleLambdaHandler {
@@ -125,30 +135,34 @@ class LambdaHandlerTest: XCTestCase {
125
135
}
126
136
127
137
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 ) " ) )
129
139
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
130
140
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
131
141
}
132
142
133
143
func testVoidHandlerSuccess( ) {
134
144
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 " ) }
136
148
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
137
149
138
150
struct Handler : SimpleLambdaHandler {
139
151
func handle( _ event: String , context: LambdaContext ) async throws { }
140
152
}
141
153
142
154
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 ) " ) )
144
156
145
157
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
146
158
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
147
159
}
148
160
149
161
func testHandlerFailure( ) {
150
162
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 " ) }
152
166
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
153
167
154
168
struct Handler : SimpleLambdaHandler {
@@ -158,7 +172,7 @@ class LambdaHandlerTest: XCTestCase {
158
172
}
159
173
160
174
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 ) " ) )
162
176
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
163
177
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
164
178
}
@@ -167,7 +181,9 @@ class LambdaHandlerTest: XCTestCase {
167
181
168
182
func testEventLoopSuccess( ) {
169
183
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 " ) }
171
187
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
172
188
173
189
struct Handler : EventLoopLambdaHandler {
@@ -181,14 +197,16 @@ class LambdaHandlerTest: XCTestCase {
181
197
}
182
198
183
199
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 ) " ) )
185
201
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
186
202
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
187
203
}
188
204
189
205
func testVoidEventLoopSuccess( ) {
190
206
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 " ) }
192
210
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
193
211
194
212
struct Handler : EventLoopLambdaHandler {
@@ -202,14 +220,16 @@ class LambdaHandlerTest: XCTestCase {
202
220
}
203
221
204
222
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 ) " ) )
206
224
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
207
225
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
208
226
}
209
227
210
228
func testEventLoopFailure( ) {
211
229
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 " ) }
213
233
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
214
234
215
235
struct Handler : EventLoopLambdaHandler {
@@ -223,14 +243,16 @@ class LambdaHandlerTest: XCTestCase {
223
243
}
224
244
225
245
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 ) " ) )
227
247
let result = Lambda . run ( configuration: configuration, handlerType: Handler . self)
228
248
assertLambdaRuntimeResult ( result, shouldHaveRun: maxTimes)
229
249
}
230
250
231
251
func testEventLoopBootstrapFailure( ) {
232
252
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 " ) }
234
256
defer { XCTAssertNoThrow ( try server. stop ( ) . wait ( ) ) }
235
257
236
258
struct Handler : EventLoopLambdaHandler {
@@ -244,7 +266,8 @@ class LambdaHandlerTest: XCTestCase {
244
266
}
245
267
}
246
268
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)
248
271
assertLambdaRuntimeResult ( result, shouldFailWithError: TestError ( " kaboom " ) )
249
272
}
250
273
}
0 commit comments