Skip to content

Commit 8ce7be7

Browse files
committed
testing
1 parent f40a4e5 commit 8ce7be7

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/test/groovy/graphql/execution/instrumentation/dataloader/DeferWithDataLoaderTest.groovy

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import spock.lang.Unroll
1818
import java.util.concurrent.CompletableFuture
1919

2020
import static graphql.ExperimentalApi.ENABLE_INCREMENTAL_SUPPORT
21+
import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING
22+
import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING
2123
import static graphql.execution.instrumentation.dataloader.DataLoaderPerformanceData.combineExecutionResults
2224
import static graphql.execution.instrumentation.dataloader.DataLoaderPerformanceData.expectedData
2325
import static graphql.execution.instrumentation.dataloader.DataLoaderPerformanceData.expectedExpensiveData
@@ -83,9 +85,7 @@ class DeferWithDataLoaderTest extends Specification {
8385
.dataLoaderRegistry(dataLoaderRegistry)
8486
.graphQLContext([(ENABLE_INCREMENTAL_SUPPORT): true])
8587
.build()
86-
if (exhaustedStrategy) {
87-
executionInput.getGraphQLContext().put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, true)
88-
}
88+
executionInput.getGraphQLContext().putAll(contextKey == null ? Collections.emptyMap() : [(contextKey): true])
8989

9090
IncrementalExecutionResult result = graphQL.execute(executionInput)
9191

@@ -109,7 +109,7 @@ class DeferWithDataLoaderTest extends Specification {
109109
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 3
110110

111111
where:
112-
exhaustedStrategy << [false, true]
112+
contextKey << [ENABLE_DATA_LOADER_CHAINING, ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, null]
113113
}
114114

115115
@Unroll
@@ -147,9 +147,7 @@ class DeferWithDataLoaderTest extends Specification {
147147
.dataLoaderRegistry(dataLoaderRegistry)
148148
.graphQLContext([(ENABLE_INCREMENTAL_SUPPORT): true])
149149
.build()
150-
if (exhaustedStrategy) {
151-
executionInput.getGraphQLContext().put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, true)
152-
}
150+
executionInput.getGraphQLContext().putAll(contextKey == null ? Collections.emptyMap() : [(contextKey): true])
153151

154152
IncrementalExecutionResult result = graphQL.execute(executionInput)
155153

@@ -189,7 +187,7 @@ class DeferWithDataLoaderTest extends Specification {
189187
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 0
190188

191189
where:
192-
exhaustedStrategy << [false, true]
190+
contextKey << [ENABLE_DATA_LOADER_CHAINING, ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, null]
193191

194192
}
195193

@@ -215,9 +213,7 @@ class DeferWithDataLoaderTest extends Specification {
215213
.dataLoaderRegistry(dataLoaderRegistry)
216214
.graphQLContext([(ENABLE_INCREMENTAL_SUPPORT): true])
217215
.build()
218-
if (exhaustedStrategy) {
219-
executionInput.getGraphQLContext().put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, true)
220-
}
216+
executionInput.getGraphQLContext().putAll(contextKey == null ? Collections.emptyMap() : [(contextKey): true])
221217

222218

223219
ExecutionResult result = graphQL.execute(executionInput)
@@ -249,7 +245,7 @@ class DeferWithDataLoaderTest extends Specification {
249245
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 9
250246

251247
where:
252-
exhaustedStrategy << [false, true]
248+
contextKey << [ENABLE_DATA_LOADER_CHAINING, ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, null]
253249

254250
}
255251

@@ -287,9 +283,7 @@ class DeferWithDataLoaderTest extends Specification {
287283
.dataLoaderRegistry(dataLoaderRegistry)
288284
.graphQLContext([(ENABLE_INCREMENTAL_SUPPORT): true])
289285
.build()
290-
if (exhaustedStrategy) {
291-
executionInput.getGraphQLContext().put(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, true)
292-
}
286+
executionInput.getGraphQLContext().putAll(contextKey == null ? Collections.emptyMap() : [(contextKey): true])
293287

294288

295289
IncrementalExecutionResult result = graphQL.execute(executionInput)
@@ -321,11 +315,12 @@ class DeferWithDataLoaderTest extends Specification {
321315
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 0
322316

323317
where:
324-
exhaustedStrategy << [false, true]
318+
contextKey << [ENABLE_DATA_LOADER_CHAINING, ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, null]
325319

326320
}
327321

328322
@Unroll
323+
@RepeatUntilFailure(maxAttempts = 5, ignoreRest = false)
329324
def "query with multiple deferred fields"() {
330325
given:
331326
def query = getExpensiveQuery(true)
@@ -351,6 +346,7 @@ class DeferWithDataLoaderTest extends Specification {
351346
.dataLoaderRegistry(dataLoaderRegistry)
352347
.graphQLContext([(ENABLE_INCREMENTAL_SUPPORT): true])
353348
.build()
349+
executionInput.getGraphQLContext().putAll(contextKey == null ? Collections.emptyMap() : [(contextKey): true])
354350

355351
IncrementalExecutionResult result = graphQL.execute(executionInput)
356352

@@ -378,12 +374,11 @@ class DeferWithDataLoaderTest extends Specification {
378374
combined.errors == null
379375
combined.data == expectedExpensiveData
380376

381-
// TODO: Why the load counters are only 1?
382-
batchCompareDataFetchers.departmentsForShopsBatchLoaderCounter.get() == 1
377+
batchCompareDataFetchers.departmentsForShopsBatchLoaderCounter.get() == (contextKey != ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING ? 1 : 2)
383378
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 1
384379

385380
where:
386-
exhaustedStrategy << [false, true]
381+
contextKey << [ENABLE_DATA_LOADER_CHAINING, ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, null]
387382

388383
}
389384

src/test/groovy/graphql/execution/instrumentation/dataloader/Issue1178DataLoaderDispatchTest.groovy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ import org.dataloader.DataLoaderFactory
1212
import org.dataloader.DataLoaderRegistry
1313
import spock.lang.RepeatUntilFailure
1414
import spock.lang.Specification
15+
import spock.lang.Unroll
1516

1617
import java.util.concurrent.CompletableFuture
1718
import java.util.concurrent.CompletionStage
1819
import java.util.concurrent.Executors
1920

21+
import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING
22+
import static graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING
2023
import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring
2124

2225
class Issue1178DataLoaderDispatchTest extends Specification {
2326

2427

28+
@Unroll
2529
@RepeatUntilFailure(maxAttempts = 100, ignoreRest = false)
2630
def "shouldn't dispatch twice in multithreaded env"() {
2731
setup:
@@ -81,7 +85,7 @@ class Issue1178DataLoaderDispatchTest extends Specification {
8185

8286
then: "execution shouldn't error"
8387
def ei = ExecutionInput.newExecutionInput()
84-
.graphQLContext([(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING): enableDataLoaderChaining])
88+
.graphQLContext(contextKey == null ? Collections.emptyMap() : [(contextKey): true])
8589
.dataLoaderRegistry(dataLoaderRegistry)
8690
.query("""
8791
query {
@@ -120,7 +124,7 @@ class Issue1178DataLoaderDispatchTest extends Specification {
120124
Awaitility.await().until { resultCF.isDone() }
121125
assert resultCF.get().errors.empty
122126
where:
123-
enableDataLoaderChaining << [true, false]
127+
contextKey << [ENABLE_DATA_LOADER_CHAINING, ENABLE_DATA_LOADER_EXHAUSTED_DISPATCHING, null]
124128

125129
}
126130

0 commit comments

Comments
 (0)