Skip to content

Commit

Permalink
Fix delayed result snapshot (#583)
Browse files Browse the repository at this point in the history
* Fix delayed result snapshots by cloning them before they are mutated

* Fix snapshots

* Fix more snapshots introduced later

* Kick build
  • Loading branch information
gnawf committed Sep 3, 2024
1 parent c17dd52 commit 62cfd08
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ abstract class NadelIntegrationTest(
// Note: we compare hasNext further down in the function
compareJsonObject(
expectedDelayedResult - "hasNext",
actualDelayedResult.toSpecification() - "hasNext",
actualDelayedResult - "hasNext",
).passed()
}

Expand Down Expand Up @@ -337,7 +337,10 @@ abstract class NadelIntegrationTest(
.forEach { actualCall ->
val delayedResults = actualCall.delayedResults
if (delayedResults.isNotEmpty()) {
assertTrue(delayedResults.dropLast(n = 1).all { it.hasNext() } && !delayedResults.last().hasNext())
assertTrue(
delayedResults.dropLast(n = 1).all { it["hasNext"] == true }
&& delayedResults.last()["hasNext"] == false
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestExecutionCapture {
val query: String,
val variables: JsonMap,
val result: JsonMap,
val delayedResults: List<DelayedIncrementalPartialResult>,
val delayedResults: List<JsonMap>,
)

fun capture(
Expand All @@ -38,7 +38,7 @@ class TestExecutionCapture {
variables: JsonMap,
result: ExecutionResult,
): ExecutionResult {
val delayedResults = synchronizedMutableListOf<DelayedIncrementalPartialResult>()
val delayedResults = synchronizedMutableListOf<JsonMap>()

_calls.add(
Call(
Expand All @@ -51,7 +51,7 @@ class TestExecutionCapture {
)

return spyOnIncrementalResults(result) {
delayedResults.add(it)
delayedResults.add(deepClone(it))
}
}

Expand Down Expand Up @@ -93,6 +93,10 @@ class TestExecutionCapture {
return jsonObjectMapper.convertValue(result.toSpecification()!!)
}

private fun deepClone(result: DelayedIncrementalPartialResult): JsonMap {
return jsonObjectMapper.convertValue(result.toSpecification()!!)
}

/**
* Overrides the default one to mark it as deprecated because you probably
* want the synchronized one anyway.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public class DeferredDeepRenameTestSnapshot : TestSnapshot() {
| "path": [],
| "data": {
| "details": {
| "name": "Issue-1"
| "deep_rename__name__issue": {
| "name": "Issue-1"
| },
| "__typename__deep_rename__name": "IssueDetail"
| }
| }
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class DeferredFieldIsRenamedTestSnapshot : TestSnapshot() {
| "defer"
| ],
| "data": {
| "overallString": "string for the deferred renamed field"
| "rename__overallString__underlyingString": "string for the deferred renamed field",
| "__typename__rename__overallString": "DeferApi"
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,26 @@ public class DeferredListFieldIsRenamedTestSnapshot : TestSnapshot() {
| {
| "key": "GQLGW-1",
| "assigneeId": "ari:cloud:identity::user/1",
| "awesomeIssueName": "Issue 1"
| "rename__awesomeIssueName__title": "Issue 1",
| "__typename__rename__awesomeIssueName": "Issue"
| },
| {
| "key": "GQLGW-2",
| "assigneeId": "ari:cloud:identity::user/2",
| "awesomeIssueName": "Issue 2"
| "rename__awesomeIssueName__title": "Issue 2",
| "__typename__rename__awesomeIssueName": "Issue"
| },
| {
| "key": "GQLGW-3",
| "assigneeId": "ari:cloud:identity::user/1",
| "awesomeIssueName": "Issue 3"
| "rename__awesomeIssueName__title": "Issue 3",
| "__typename__rename__awesomeIssueName": "Issue"
| },
| {
| "key": "GQLGW-4",
| "assigneeId": "ari:cloud:identity::user/3",
| "awesomeIssueName": null
| "rename__awesomeIssueName__title": null,
| "__typename__rename__awesomeIssueName": "Issue"
| }
| ]
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class MultipleRenameTransformsInsideAndOutsideDeferSnapshot : TestSnapsho
| "defer"
| ],
| "data": {
| "slowRenamedString": "this is the slow string (deferred)"
| "rename__slowRenamedString__slowString": "this is the slow string (deferred)",
| "__typename__rename__slowRenamedString": "DeferApi"
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public class MultipleRenamedFieldsAreDeferredTogetherSnapshot : TestSnapshot() {
| "defer"
| ],
| "data": {
| "overallString": "deferred string 1",
| "overallString2": "deferred string 2"
| "__typename__rename__overallString2": "DeferApi",
| "rename__overallString2__underlyingString2": "deferred string 2",
| "rename__overallString__underlyingString": "deferred string 1",
| "__typename__rename__overallString": "DeferApi"
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public class MultipleSeparateDefersWithTransformsSnapshot : TestSnapshot() {
| "defer"
| ],
| "data": {
| "slowRenamedString": "this is the slow string (deferred)"
| "rename__slowRenamedString__slowString": "this is the slow string (deferred)",
| "__typename__rename__slowRenamedString": "DeferApi"
| }
| }
| ]
Expand All @@ -76,7 +77,8 @@ public class MultipleSeparateDefersWithTransformsSnapshot : TestSnapshot() {
| "defer"
| ],
| "data": {
| "anotherSlowRenamedString": "this is the other slow string (deferred)"
| "rename__anotherSlowRenamedString__anotherSlowString": "this is the other slow string (deferred)",
| "__typename__rename__anotherSlowRenamedString": "DeferApi"
| }
| }
| ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public class RenameInnerFieldInsideDeferSnapshot : TestSnapshot() {
| ],
| "data": {
| "user": {
| "firstName": "Steven"
| "rename__firstName__name": "Steven",
| "__typename__rename__firstName": "User"
| }
| }
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class RenamedTypeIsDeferredTestSnapshot : TestSnapshot() {
| "cat"
| ],
| "data": {
| "__typename": "Cat"
| "__typename": "Rat"
| }
| }
| ]
Expand All @@ -82,7 +82,7 @@ public class RenamedTypeIsDeferredTestSnapshot : TestSnapshot() {
| "data": {
| "monkey": {
| "name": "Harambe",
| "__typename": "Monkey"
| "__typename": "Donkey"
| }
| }
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ public class HydrationRenamedFieldInDeferTestSnapshot : TestSnapshot() {
| {
| "path": [],
| "data": {
| "issueByKey": {
| "rename__issueByKey__getIssueByKey": {
| "key": "GQLGW-1",
| "assignee": {
| "name": "Franklin"
| }
| "hydration__assignee__assigneeId": "ari:cloud:identity::user/1",
| "__typename__hydration__assignee": "Issue"
| }
| }
| }
Expand Down

0 comments on commit 62cfd08

Please sign in to comment.