Skip to content

Commit 21104b8

Browse files
authored
Merge pull request #76 from NeedleInAJayStack/concurrency
2 parents a24964f + 865db66 commit 21104b8

File tree

6 files changed

+37
-33
lines changed

6 files changed

+37
-33
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919
- name: Set code coverage path
20-
run: echo ::set-env name=codecov_path::$(swift test --show-codecov-path)
20+
run: echo "codecov_path=$(swift test --show-codecov-path)" >> $GITHUB_ENV
2121
- name: Test and publish code coverage to Code Climate
2222
uses: paulofaria/codeclimate-action@master
2323
if: matrix.os == 'macos-10.15'

Sources/GraphQL/Utilities/NIO+Extensions.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extension Collection {
2828

2929
extension Dictionary where Value : FutureType {
3030
func flatten(on eventLoopGroup: EventLoopGroup) -> Future<[Key: Value.Expectation]> {
31+
let queue = DispatchQueue(label: "org.graphQL.elementQueue")
3132
var elements: [Key: Value.Expectation] = [:]
3233

3334
guard self.count > 0 else {
@@ -39,10 +40,13 @@ extension Dictionary where Value : FutureType {
3940

4041
for (key, value) in self {
4142
value.whenSuccess { expectation in
42-
elements[key] = expectation
43-
44-
if elements.count == self.count {
45-
promise.succeed(elements)
43+
// Control access to elements to avoid thread conflicts
44+
queue.async {
45+
elements[key] = expectation
46+
47+
if elements.count == self.count {
48+
promise.succeed(elements)
49+
}
4650
}
4751
}
4852

Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class FieldExecutionStrategyTests: XCTestCase {
201201
private var eventLoopGroup: EventLoopGroup!
202202

203203
override func setUp() {
204-
eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
204+
eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
205205
}
206206

207207
override func tearDown() {

Tests/GraphQLTests/HelloWorldTests/HelloWorldTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HelloWorldTests : XCTestCase {
1818
)
1919

2020
func testHello() throws {
21-
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
21+
let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
2222

2323
defer {
2424
XCTAssertNoThrow(try group.syncShutdownGracefully())
@@ -37,7 +37,7 @@ class HelloWorldTests : XCTestCase {
3737
}
3838

3939
func testBoyhowdy() throws {
40-
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
40+
let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
4141

4242
defer {
4343
XCTAssertNoThrow(try group.syncShutdownGracefully())

Tests/GraphQLTests/StarWarsTests/StarWarsIntrospectionTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NIO
55

66
class StarWarsIntrospectionTests : XCTestCase {
77
func testIntrospectionTypeQuery() throws {
8-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
8+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
99
defer {
1010
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
1111
}
@@ -81,7 +81,7 @@ class StarWarsIntrospectionTests : XCTestCase {
8181
}
8282

8383
func testIntrospectionQueryTypeQuery() throws {
84-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
84+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
8585
defer {
8686
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
8787
}
@@ -109,7 +109,7 @@ class StarWarsIntrospectionTests : XCTestCase {
109109
}
110110

111111
func testIntrospectionDroidTypeQuery() throws {
112-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
112+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
113113
defer {
114114
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
115115
}
@@ -133,7 +133,7 @@ class StarWarsIntrospectionTests : XCTestCase {
133133
}
134134

135135
func testIntrospectionDroidKindQuery() throws {
136-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
136+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
137137
defer {
138138
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
139139
}
@@ -159,7 +159,7 @@ class StarWarsIntrospectionTests : XCTestCase {
159159
}
160160

161161
func testIntrospectionCharacterKindQuery() throws {
162-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
162+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
163163
defer {
164164
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
165165
}
@@ -185,7 +185,7 @@ class StarWarsIntrospectionTests : XCTestCase {
185185
}
186186

187187
func testIntrospectionDroidFieldsQuery() throws {
188-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
188+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
189189
defer {
190190
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
191191
}
@@ -260,7 +260,7 @@ class StarWarsIntrospectionTests : XCTestCase {
260260
}
261261

262262
func testIntrospectionDroidNestedFieldsQuery() throws {
263-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
263+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
264264
defer {
265265
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
266266
}
@@ -354,7 +354,7 @@ class StarWarsIntrospectionTests : XCTestCase {
354354
}
355355

356356
func testIntrospectionFieldArgsQuery() throws {
357-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
357+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
358358
defer {
359359
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
360360
}
@@ -449,7 +449,7 @@ class StarWarsIntrospectionTests : XCTestCase {
449449
}
450450

451451
func testIntrospectionDroidDescriptionQuery() throws {
452-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
452+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
453453
defer {
454454
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
455455
}

Tests/GraphQLTests/StarWarsTests/StarWarsQueryTests.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NIO
55

66
class StarWarsQueryTests : XCTestCase {
77
func testHeroNameQuery() throws {
8-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
8+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
99

1010
defer {
1111
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
@@ -37,7 +37,7 @@ class StarWarsQueryTests : XCTestCase {
3737
}
3838

3939
func testHeroNameAndFriendsQuery() throws {
40-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
40+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
4141

4242
defer {
4343
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
@@ -79,7 +79,7 @@ class StarWarsQueryTests : XCTestCase {
7979
}
8080

8181
func testNestedQuery() throws {
82-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
82+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
8383

8484
defer {
8585
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
@@ -144,7 +144,7 @@ class StarWarsQueryTests : XCTestCase {
144144
}
145145

146146
func testFetchLukeQuery() throws {
147-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
147+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
148148
defer {
149149
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
150150
}
@@ -168,7 +168,7 @@ class StarWarsQueryTests : XCTestCase {
168168
}
169169

170170
func testOptionalVariable() throws{
171-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
171+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
172172
defer {
173173
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
174174
}
@@ -215,7 +215,7 @@ class StarWarsQueryTests : XCTestCase {
215215
}
216216

217217
func testFetchSomeIDQuery() throws {
218-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
218+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
219219
defer {
220220
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
221221
}
@@ -276,7 +276,7 @@ class StarWarsQueryTests : XCTestCase {
276276
}
277277

278278
func testFetchLukeAliasedQuery() throws {
279-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
279+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
280280
defer {
281281
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
282282
}
@@ -300,7 +300,7 @@ class StarWarsQueryTests : XCTestCase {
300300
}
301301

302302
func testFetchLukeAndLeiaAliasedQuery() throws {
303-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
303+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
304304
defer {
305305
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
306306
}
@@ -330,7 +330,7 @@ class StarWarsQueryTests : XCTestCase {
330330
}
331331

332332
func testDuplicateFieldsQuery() throws {
333-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
333+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
334334
defer {
335335
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
336336
}
@@ -364,7 +364,7 @@ class StarWarsQueryTests : XCTestCase {
364364
}
365365

366366
func testUseFragmentQuery() throws {
367-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
367+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
368368
defer {
369369
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
370370
}
@@ -400,7 +400,7 @@ class StarWarsQueryTests : XCTestCase {
400400
}
401401

402402
func testCheckTypeOfR2Query() throws {
403-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
403+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
404404
defer {
405405
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
406406
}
@@ -431,7 +431,7 @@ class StarWarsQueryTests : XCTestCase {
431431
}
432432

433433
func testCheckTypeOfLukeQuery() throws {
434-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
434+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
435435
defer {
436436
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
437437
}
@@ -457,7 +457,7 @@ class StarWarsQueryTests : XCTestCase {
457457
}
458458

459459
func testSecretBackstoryQuery() throws {
460-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
460+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
461461
defer {
462462
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
463463
}
@@ -490,7 +490,7 @@ class StarWarsQueryTests : XCTestCase {
490490
}
491491

492492
func testSecretBackstoryListQuery() throws {
493-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
493+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
494494
defer {
495495
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
496496
}
@@ -549,7 +549,7 @@ class StarWarsQueryTests : XCTestCase {
549549
}
550550

551551
func testSecretBackstoryAliasQuery() throws {
552-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
552+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
553553
defer {
554554
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
555555
}
@@ -582,7 +582,7 @@ class StarWarsQueryTests : XCTestCase {
582582
}
583583

584584
func testNonNullableFieldsQuery() throws {
585-
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
585+
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
586586
defer {
587587
XCTAssertNoThrow(try eventLoopGroup.syncShutdownGracefully())
588588
}

0 commit comments

Comments
 (0)