Skip to content

Update spec tests from changes in the firebase-js-sdk respository #1401

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 5 commits into from
Apr 3, 2020
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 @@ -95,6 +95,7 @@
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.json.JSONArray;
Expand Down Expand Up @@ -176,7 +177,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
private Map<Query, QueryListener> queryListeners;

/** Set of documents that are expected to be in limbo. Verified at every step. */
private Set<DocumentKey> expectedLimboDocs;
private Set<DocumentKey> expectedActiveLimboDocs;

/** Set of expected active targets, keyed by target ID. */
private Map<Integer, Pair<List<TargetData>, String>> expectedActiveTargets;
Expand Down Expand Up @@ -263,7 +264,7 @@ protected void specSetUp(JSONObject config) {
events = new ArrayList<>();
queryListeners = new HashMap<>();

expectedLimboDocs = new HashSet<>();
expectedActiveLimboDocs = new HashSet<>();
expectedActiveTargets = new HashMap<>();

snapshotsInSyncListeners = Collections.synchronizedList(new ArrayList<>());
Expand Down Expand Up @@ -910,11 +911,11 @@ private void validateExpectedState(@Nullable JSONObject expectedState) throws JS
expectedState.getInt("watchStreamRequestCount"),
datastore.getWatchStreamRequestCount());
}
if (expectedState.has("limboDocs")) {
expectedLimboDocs = new HashSet<>();
JSONArray limboDocs = expectedState.getJSONArray("limboDocs");
if (expectedState.has("activeLimboDocs")) {
expectedActiveLimboDocs = new HashSet<>();
JSONArray limboDocs = expectedState.getJSONArray("activeLimboDocs");
for (int i = 0; i < limboDocs.length(); i++) {
expectedLimboDocs.add(key((String) limboDocs.get(i)));
expectedActiveLimboDocs.add(key((String) limboDocs.get(i)));
}
}
if (expectedState.has("activeTargets")) {
Expand Down Expand Up @@ -989,20 +990,28 @@ private void validateLimboDocs() {
Map<DocumentKey, Integer> actualLimboDocs =
new HashMap<>(syncEngine.getCurrentLimboDocuments());

// Validate that each limbo doc has an expected active target
// Validate that each active limbo doc has an expected active target
for (Map.Entry<DocumentKey, Integer> limboDoc : actualLimboDocs.entrySet()) {
assertTrue(
"Found limbo doc " + limboDoc.getKey() + " without an expected active target",
"Found limbo doc "
+ limboDoc.getKey()
+ ", but its target ID "
+ limboDoc.getValue()
+ " was not in the set of expected active target IDs "
+ expectedActiveTargets.keySet().stream()
.sorted()
.map(String::valueOf)
.collect(Collectors.joining(", ")),
expectedActiveTargets.containsKey(limboDoc.getValue()));
}

for (DocumentKey expectedLimboDoc : expectedLimboDocs) {
for (DocumentKey expectedLimboDoc : expectedActiveLimboDocs) {
assertTrue(
"Expected doc to be in limbo, but was not: " + expectedLimboDoc,
actualLimboDocs.containsKey(expectedLimboDoc));
actualLimboDocs.remove(expectedLimboDoc);
}
assertTrue("Unexpected docs in limbo: " + actualLimboDocs, actualLimboDocs.isEmpty());
assertTrue("Unexpected active docs in limbo: " + actualLimboDocs, actualLimboDocs.isEmpty());
}

private void validateActiveTargets() {
Expand Down
109 changes: 62 additions & 47 deletions firebase-firestore/src/test/resources/json/collection_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
"Events are raised after watch ack": {
"describeName": "Collections:",
"itName": "Events are raised after watch ack",
"tags": [],
"tags": [
],
"config": {
"useGarbageCollection": true,
"numClients": 1
"numClients": 1,
"useGarbageCollection": true
},
"steps": [
{
"userListen": [
2,
{
"path": "collection",
"filters": [],
"orderBys": []
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"path": "collection",
"filters": [],
"orderBys": []
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": ""
Expand All @@ -42,14 +47,14 @@
"docs": [
{
"key": "collection/key",
"version": 1000,
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"foo": "bar"
},
"options": {
"hasLocalMutations": false,
"hasCommittedMutations": false
}
"version": 1000
}
],
"targets": [
Expand All @@ -67,32 +72,35 @@
},
{
"watchSnapshot": {
"version": 1001,
"targetIds": []
"targetIds": [
],
"version": 1001
},
"expectedSnapshotEvents": [
{
"query": {
"path": "collection",
"filters": [],
"orderBys": []
},
"added": [
{
"key": "collection/key",
"version": 1000,
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": false
},
"value": {
"foo": "bar"
},
"options": {
"hasLocalMutations": false,
"hasCommittedMutations": false
}
"version": 1000
}
],
"errorCode": 0,
"fromCache": false,
"hasPendingWrites": false
"hasPendingWrites": false,
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
}
}
]
}
Expand All @@ -101,29 +109,34 @@
"Events are raised for local sets before watch ack": {
"describeName": "Collections:",
"itName": "Events are raised for local sets before watch ack",
"tags": [],
"tags": [
],
"config": {
"useGarbageCollection": true,
"numClients": 1
"numClients": 1,
"useGarbageCollection": true
},
"steps": [
{
"userListen": [
2,
{
"path": "collection",
"filters": [],
"orderBys": []
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"expectedState": {
"activeTargets": {
"2": {
"queries": [
{
"path": "collection",
"filters": [],
"orderBys": []
"filters": [
],
"orderBys": [
],
"path": "collection"
}
],
"resumeToken": ""
Expand All @@ -140,27 +153,29 @@
],
"expectedSnapshotEvents": [
{
"query": {
"path": "collection",
"filters": [],
"orderBys": []
},
"added": [
{
"key": "collection/key",
"version": 0,
"options": {
"hasCommittedMutations": false,
"hasLocalMutations": true
},
"value": {
"foo": "bar"
},
"options": {
"hasLocalMutations": true,
"hasCommittedMutations": false
}
"version": 0
}
],
"errorCode": 0,
"fromCache": true,
"hasPendingWrites": true
"hasPendingWrites": true,
"query": {
"filters": [
],
"orderBys": [
],
"path": "collection"
}
}
]
}
Expand Down
Loading