Skip to content

Commit d9d3136

Browse files
Fix flaky defer test
The order of incremental data in the scenario being tested was non-deterministic, so the test needed a few adjustments
1 parent b8b969e commit d9d3136

1 file changed

Lines changed: 32 additions & 32 deletions

File tree

src/test/groovy/graphql/execution/incremental/DeferExecutionSupportIntegrationTest.groovy

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package graphql.execution.incremental
22

3+
import com.google.common.collect.Iterables
34
import graphql.Directives
45
import graphql.ExecutionInput
56
import graphql.ExecutionResult
67
import graphql.ExperimentalApi
78
import graphql.GraphQL
8-
import graphql.GraphQLContext
99
import graphql.TestUtil
1010
import graphql.execution.pubsub.CapturingSubscriber
1111
import graphql.incremental.DelayedIncrementalPartialResult
@@ -254,9 +254,9 @@ class DeferExecutionSupportIntegrationTest extends Specification {
254254
id2: id
255255
}
256256
}
257-
... @defer {
257+
... @defer(label: "defer-post3") {
258258
post3: postById(id: "3") {
259-
... @defer {
259+
... @defer(label: "defer-id3") {
260260
id3: id
261261
}
262262
}
@@ -277,35 +277,35 @@ class DeferExecutionSupportIntegrationTest extends Specification {
277277
def incrementalResults = getIncrementalResults(initialResult)
278278

279279
then:
280-
incrementalResults == [
281-
[
282-
hasNext : true,
283-
incremental: [
284-
[
285-
path: [],
286-
data: [post2: [id2: "2"]]
287-
]
288-
]
289-
],
290-
[
291-
hasNext : true,
292-
incremental: [
293-
[
294-
path: [],
295-
data: [post3: [:]]
296-
]
297-
]
298-
],
299-
[
300-
hasNext : false,
301-
incremental: [
302-
[
303-
path: ["post3"],
304-
data: [id3: "3"]
305-
]
306-
]
307-
]
308-
]
280+
// Ordering is non-deterministic, so we assert on the things we know are going to be true.
281+
282+
incrementalResults.size() == 3
283+
// only the last payload has "hasNext=true"
284+
incrementalResults[0].hasNext == true
285+
incrementalResults[1].hasNext == true
286+
incrementalResults[2].hasNext == false
287+
288+
// every payload has only 1 incremental item
289+
incrementalResults.every { it.incremental.size() == 1 }
290+
291+
incrementalResults.any {
292+
it.incremental[0] == [path: [], data: [post2: [id2: "2"]]]
293+
}
294+
295+
// id3 HAS TO be delivered after post3
296+
def indexOfPost3 = Iterables.indexOf(incrementalResults, {
297+
it.incremental[0] == [path: [], label: "defer-post3", data: [post3: [:]]]
298+
})
299+
300+
def indexOfId3 = Iterables.indexOf(incrementalResults, {
301+
it.incremental[0] == [path: ["post3"], label:"defer-id3", data: [id3: "3"]]
302+
})
303+
304+
// Assert that both post3 and id3 are present
305+
indexOfPost3 >= 0
306+
indexOfId3 >= 0
307+
// Assert that id3 is delivered after post3
308+
indexOfId3 > indexOfPost3
309309
}
310310

311311
def "defer on interface field"() {

0 commit comments

Comments
 (0)