1
1
import Dispatch
2
2
import GraphQL
3
3
import XCTest
4
+ import NIO
4
5
5
6
class FieldExecutionStrategyTests : XCTestCase {
6
7
@@ -14,14 +15,14 @@ class FieldExecutionStrategyTests: XCTestCase {
14
15
fields: [
15
16
" sleep " : GraphQLField (
16
17
type: GraphQLString,
17
- resolve: { _, _, _ , _ in
18
+ resolve: { _, _, eventLoopGroup , _ in
18
19
let g = DispatchGroup ( )
19
20
g. enter ( )
20
21
DispatchQueue . global ( ) . asyncAfter ( wallDeadline: . now( ) + 0.1 ) {
21
22
g. leave ( )
22
23
}
23
24
g. wait ( )
24
- return " z "
25
+ return eventLoopGroup . next ( ) . newSucceededFuture ( result : " z " )
25
26
}
26
27
) ,
27
28
" bang " : GraphQLField (
@@ -179,41 +180,65 @@ class FieldExecutionStrategyTests: XCTestCase {
179
180
}
180
181
181
182
func testSerialFieldExecutionStrategyWithSingleField( ) throws {
183
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
184
+ defer {
185
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
186
+ }
187
+
182
188
let result = try timing ( try graphql (
183
189
queryStrategy: SerialFieldExecutionStrategy ( ) ,
184
190
schema: schema,
185
- request: singleQuery
186
- ) )
191
+ request: singleQuery,
192
+ eventLoopGroup: eventLoopGroup
193
+ ) . wait ( ) )
187
194
XCTAssertEqual ( result. value, singleExpected)
188
195
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
189
196
}
190
197
191
198
func testSerialFieldExecutionStrategyWithSingleFieldError( ) throws {
199
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
200
+ defer {
201
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
202
+ }
203
+
192
204
let result = try timing ( try graphql (
193
205
queryStrategy: SerialFieldExecutionStrategy ( ) ,
194
206
schema: schema,
195
- request: singleThrowsQuery
196
- ) )
207
+ request: singleThrowsQuery,
208
+ eventLoopGroup: eventLoopGroup
209
+ ) . wait ( ) )
197
210
XCTAssertEqual ( result. value, singleThrowsExpected)
198
211
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
199
212
}
200
213
201
214
func testSerialFieldExecutionStrategyWithMultipleFields( ) throws {
215
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
216
+ defer {
217
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
218
+ }
219
+
202
220
let result = try timing ( try graphql (
203
221
queryStrategy: SerialFieldExecutionStrategy ( ) ,
204
222
schema: schema,
205
- request: multiQuery
206
- ) )
223
+ request: multiQuery,
224
+ eventLoopGroup: eventLoopGroup
225
+ ) . wait ( ) )
207
226
XCTAssertEqual ( result. value, multiExpected)
208
227
//XCTAssertEqualWithAccuracy(1.0, result.seconds, accuracy: 0.5)
209
228
}
210
229
211
230
func testSerialFieldExecutionStrategyWithMultipleFieldErrors( ) throws {
231
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
232
+ defer {
233
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
234
+ }
235
+
212
236
let result = try timing ( try graphql (
213
237
queryStrategy: SerialFieldExecutionStrategy ( ) ,
214
238
schema: schema,
215
- request: multiThrowsQuery
216
- ) )
239
+ request: multiThrowsQuery,
240
+ eventLoopGroup: eventLoopGroup
241
+ ) . wait ( ) )
217
242
XCTAssertEqual ( result. value [ " data " ] , multiThrowsExpectedData)
218
243
let resultErrors = try result. value [ " errors " ] . asArray ( )
219
244
XCTAssertEqual ( resultErrors. count, multiThrowsExpectedErrors. count)
@@ -224,41 +249,65 @@ class FieldExecutionStrategyTests: XCTestCase {
224
249
}
225
250
226
251
func testConcurrentDispatchFieldExecutionStrategyWithSingleField( ) throws {
252
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
253
+ defer {
254
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
255
+ }
256
+
227
257
let result = try timing ( try graphql (
228
258
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
229
259
schema: schema,
230
- request: singleQuery
231
- ) )
260
+ request: singleQuery,
261
+ eventLoopGroup: eventLoopGroup
262
+ ) . wait ( ) )
232
263
XCTAssertEqual ( result. value, singleExpected)
233
264
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
234
265
}
235
266
236
267
func testConcurrentDispatchFieldExecutionStrategyWithSingleFieldError( ) throws {
268
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
269
+ defer {
270
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
271
+ }
272
+
237
273
let result = try timing ( try graphql (
238
274
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
239
275
schema: schema,
240
- request: singleThrowsQuery
241
- ) )
276
+ request: singleThrowsQuery,
277
+ eventLoopGroup: eventLoopGroup
278
+ ) . wait ( ) )
242
279
XCTAssertEqual ( result. value, singleThrowsExpected)
243
280
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
244
281
}
245
282
246
283
func testConcurrentDispatchFieldExecutionStrategyWithMultipleFields( ) throws {
284
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
285
+ defer {
286
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
287
+ }
288
+
247
289
let result = try timing ( try graphql (
248
290
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
249
291
schema: schema,
250
- request: multiQuery
251
- ) )
292
+ request: multiQuery,
293
+ eventLoopGroup: eventLoopGroup
294
+ ) . wait ( ) )
252
295
XCTAssertEqual ( result. value, multiExpected)
253
296
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
254
297
}
255
298
256
299
func testConcurrentDispatchFieldExecutionStrategyWithMultipleFieldErrors( ) throws {
300
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
301
+ defer {
302
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
303
+ }
304
+
257
305
let result = try timing ( try graphql (
258
306
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
259
307
schema: schema,
260
- request: multiThrowsQuery
261
- ) )
308
+ request: multiThrowsQuery,
309
+ eventLoopGroup: eventLoopGroup
310
+ ) . wait ( ) )
262
311
XCTAssertEqual ( result. value [ " data " ] , multiThrowsExpectedData)
263
312
let resultErrors = try result. value [ " errors " ] . asArray ( )
264
313
XCTAssertEqual ( resultErrors. count, multiThrowsExpectedErrors. count)
0 commit comments