@@ -38,6 +38,20 @@ class FieldExecutionStrategyTests: XCTestCase {
38
38
msg: " \( info. fieldName) : \( info. path. last as! String ) "
39
39
)
40
40
}
41
+ ) ,
42
+ " futureBang " : GraphQLField (
43
+ type: GraphQLString,
44
+ resolve: { ( _, _, _, eventLoopGroup, info: GraphQLResolveInfo ) in
45
+ let g = DispatchGroup ( )
46
+ g. enter ( )
47
+ DispatchQueue . global ( ) . asyncAfter ( wallDeadline: . now( ) + 0.1 ) {
48
+ g. leave ( )
49
+ }
50
+ g. wait ( )
51
+ return eventLoopGroup. next ( ) . newFailedFuture ( error: StrategyError . exampleError (
52
+ msg: " \( info. fieldName) : \( info. path. last as! String ) "
53
+ ) )
54
+ }
41
55
)
42
56
]
43
57
)
@@ -81,8 +95,24 @@ class FieldExecutionStrategyTests: XCTestCase {
81
95
]
82
96
]
83
97
]
98
+
99
+ let singleFailedFutureQuery = " { futureBang } "
100
+ let singleFailedFutureExpected : Map = [
101
+ " data " : [
102
+ " futureBang " : nil
103
+ ] ,
104
+ " errors " : [
105
+ [
106
+ " locations " : [
107
+ [ " column " : 3 , " line " : 1 ]
108
+ ] ,
109
+ " message " : " exampleError(msg: \" futureBang: futureBang \" ) " ,
110
+ " path " : [ " futureBang " ]
111
+ ]
112
+ ]
113
+ ]
84
114
85
- let multiThrowsQuery = " { a: bang b: bang c: bang d: bang e: bang f: bang g: bang h: bang i: bang j: bang } "
115
+ let multiThrowsQuery = " { a: bang b: bang c: bang d: bang e: bang f: bang g: bang h: bang i: bang j: futureBang } "
86
116
let multiThrowsExpectedData : Map = [
87
117
" a " : nil ,
88
118
" b " : nil ,
@@ -163,7 +193,7 @@ class FieldExecutionStrategyTests: XCTestCase {
163
193
" locations " : [
164
194
[ " column " : 75 , " line " : 1 ]
165
195
] ,
166
- " message " : " exampleError(msg: \" bang : j\" ) " ,
196
+ " message " : " exampleError(msg: \" futureBang : j\" ) " ,
167
197
" path " : [ " j " ]
168
198
] ,
169
199
]
@@ -178,12 +208,18 @@ class FieldExecutionStrategyTests: XCTestCase {
178
208
seconds: seconds
179
209
)
180
210
}
211
+
212
+ private var eventLoopGroup : EventLoopGroup !
213
+
214
+ override func setUp( ) {
215
+ eventLoopGroup = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
216
+ }
217
+
218
+ override func tearDown( ) {
219
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
220
+ }
181
221
182
222
func testSerialFieldExecutionStrategyWithSingleField( ) throws {
183
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
184
- defer {
185
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
186
- }
187
223
188
224
let result = try timing ( try graphql (
189
225
queryStrategy: SerialFieldExecutionStrategy ( ) ,
@@ -196,11 +232,7 @@ class FieldExecutionStrategyTests: XCTestCase {
196
232
}
197
233
198
234
func testSerialFieldExecutionStrategyWithSingleFieldError( ) throws {
199
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
200
- defer {
201
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
202
- }
203
-
235
+
204
236
let result = try timing ( try graphql (
205
237
queryStrategy: SerialFieldExecutionStrategy ( ) ,
206
238
schema: schema,
@@ -210,12 +242,20 @@ class FieldExecutionStrategyTests: XCTestCase {
210
242
XCTAssertEqual ( result. value, singleThrowsExpected)
211
243
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
212
244
}
245
+
246
+ func testSerialFieldExecutionStrategyWithSingleFieldFailedFuture( ) throws {
247
+
248
+ let result = try timing ( try graphql (
249
+ queryStrategy: SerialFieldExecutionStrategy ( ) ,
250
+ schema: schema,
251
+ request: singleFailedFutureQuery,
252
+ eventLoopGroup: eventLoopGroup
253
+ ) . wait ( ) )
254
+ XCTAssertEqual ( result. value, singleFailedFutureExpected)
255
+ //XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
256
+ }
213
257
214
258
func testSerialFieldExecutionStrategyWithMultipleFields( ) throws {
215
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
216
- defer {
217
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
218
- }
219
259
220
260
let result = try timing ( try graphql (
221
261
queryStrategy: SerialFieldExecutionStrategy ( ) ,
@@ -228,10 +268,6 @@ class FieldExecutionStrategyTests: XCTestCase {
228
268
}
229
269
230
270
func testSerialFieldExecutionStrategyWithMultipleFieldErrors( ) throws {
231
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
232
- defer {
233
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
234
- }
235
271
236
272
let result = try timing ( try graphql (
237
273
queryStrategy: SerialFieldExecutionStrategy ( ) ,
@@ -249,10 +285,6 @@ class FieldExecutionStrategyTests: XCTestCase {
249
285
}
250
286
251
287
func testConcurrentDispatchFieldExecutionStrategyWithSingleField( ) throws {
252
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
253
- defer {
254
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
255
- }
256
288
257
289
let result = try timing ( try graphql (
258
290
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
@@ -265,10 +297,6 @@ class FieldExecutionStrategyTests: XCTestCase {
265
297
}
266
298
267
299
func testConcurrentDispatchFieldExecutionStrategyWithSingleFieldError( ) throws {
268
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
269
- defer {
270
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
271
- }
272
300
273
301
let result = try timing ( try graphql (
274
302
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
@@ -281,10 +309,6 @@ class FieldExecutionStrategyTests: XCTestCase {
281
309
}
282
310
283
311
func testConcurrentDispatchFieldExecutionStrategyWithMultipleFields( ) throws {
284
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
285
- defer {
286
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
287
- }
288
312
289
313
let result = try timing ( try graphql (
290
314
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
@@ -297,10 +321,6 @@ class FieldExecutionStrategyTests: XCTestCase {
297
321
}
298
322
299
323
func testConcurrentDispatchFieldExecutionStrategyWithMultipleFieldErrors( ) throws {
300
- let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
301
- defer {
302
- XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
303
- }
304
324
305
325
let result = try timing ( try graphql (
306
326
queryStrategy: ConcurrentDispatchFieldExecutionStrategy ( ) ,
@@ -324,6 +344,7 @@ extension FieldExecutionStrategyTests {
324
344
return [
325
345
( " testSerialFieldExecutionStrategyWithSingleField " , testSerialFieldExecutionStrategyWithSingleField) ,
326
346
( " testSerialFieldExecutionStrategyWithSingleFieldError " , testSerialFieldExecutionStrategyWithSingleFieldError) ,
347
+ ( " testSerialFieldExecutionStrategyWithSingleFieldFailedFuture " , testSerialFieldExecutionStrategyWithSingleFieldFailedFuture) ,
327
348
( " testSerialFieldExecutionStrategyWithMultipleFields " , testSerialFieldExecutionStrategyWithMultipleFields) ,
328
349
( " testSerialFieldExecutionStrategyWithMultipleFieldErrors " , testSerialFieldExecutionStrategyWithMultipleFieldErrors) ,
329
350
( " testConcurrentDispatchFieldExecutionStrategyWithSingleField " , testConcurrentDispatchFieldExecutionStrategyWithSingleField) ,
0 commit comments