Skip to content

Validate query purpose in spec tests #4770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,14 @@ private void validateExpectedState(@Nullable JSONObject expectedState) throws JS
expectedActiveTargets.put(targetId, new ArrayList<>());
for (int i = 0; i < queryArrayJson.length(); i++) {
Query query = parseQuery(queryArrayJson.getJSONObject(i));
// TODO: populate the purpose of the target once it's possible to encode that in the
// spec tests. For now, hard-code that it's a listen despite the fact that it's not
// always the right value.

QueryPurpose purpose = QueryPurpose.LISTEN;
if (queryDataJson.has("targetPurpose")) {
purpose = QueryPurpose.values()[queryDataJson.getInt("targetPurpose")];
}

TargetData targetData =
new TargetData(
query.toTarget(), targetId, ARBITRARY_SEQUENCE_NUMBER, QueryPurpose.LISTEN);
new TargetData(query.toTarget(), targetId, ARBITRARY_SEQUENCE_NUMBER, purpose);
if (queryDataJson.has("resumeToken")) {
targetData =
targetData.withResumeToken(
Expand Down Expand Up @@ -1134,9 +1136,12 @@ private void validateActiveTargets() {
TargetData expectedTarget = expectedQueries.get(0);
TargetData actualTarget = actualTargets.get(expected.getKey());

// TODO: validate the purpose of the target once it's possible to encode that in the
// spec tests. For now, only validate properties that can be validated.
// TODO: Replace the assertEquals() checks on the individual properties of TargetData below
// with the single assertEquals on the TargetData objects themselves if the sequenceNumber is
// ever made to be consistent.
// assertEquals(expectedTarget, actualTarget);

assertEquals(expectedTarget.getPurpose(), actualTarget.getPurpose());
assertEquals(expectedTarget.getTarget(), actualTarget.getTarget());
assertEquals(expectedTarget.getTargetId(), actualTarget.getTargetId());
assertEquals(expectedTarget.getSnapshotVersion(), actualTarget.getSnapshotVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,8 @@
"path": "collection/a"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,24 @@
"path": "collection"
}
}
]
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": "",
"targetPurpose": 1
}
}
}
},
{
"restart": true,
Expand Down Expand Up @@ -414,7 +431,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -910,7 +928,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -976,7 +995,8 @@
"path": "collection/2"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand All @@ -988,7 +1008,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1043,7 +1064,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1475,7 +1497,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1541,7 +1564,8 @@
"path": "collection/2"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand All @@ -1553,7 +1577,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1618,7 +1643,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1822,7 +1848,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1888,7 +1915,8 @@
"path": "collection/2"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 2
},
"2": {
"queries": [
Expand All @@ -1900,7 +1928,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -1965,7 +1994,8 @@
"path": "collection"
}
],
"resumeToken": ""
"resumeToken": "",
"targetPurpose": 1
}
}
}
Expand Down Expand Up @@ -2219,7 +2249,24 @@
"path": "collection"
}
}
]
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": "",
"targetPurpose": 1
}
}
}
}
]
}
Expand Down
Loading