Skip to content

Commit f0bda45

Browse files
authored
Update spec tests from changes in the firebase-js-sdk respository (#1401)
1 parent 37721c0 commit f0bda45

14 files changed

+197842
-184475
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import java.util.Set;
9696
import java.util.logging.Logger;
9797
import java.util.regex.Pattern;
98+
import java.util.stream.Collectors;
9899
import java.util.stream.Stream;
99100
import javax.annotation.Nullable;
100101
import org.json.JSONArray;
@@ -176,7 +177,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
176177
private Map<Query, QueryListener> queryListeners;
177178

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

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

266-
expectedLimboDocs = new HashSet<>();
267+
expectedActiveLimboDocs = new HashSet<>();
267268
expectedActiveTargets = new HashMap<>();
268269

269270
snapshotsInSyncListeners = Collections.synchronizedList(new ArrayList<>());
@@ -910,11 +911,11 @@ private void validateExpectedState(@Nullable JSONObject expectedState) throws JS
910911
expectedState.getInt("watchStreamRequestCount"),
911912
datastore.getWatchStreamRequestCount());
912913
}
913-
if (expectedState.has("limboDocs")) {
914-
expectedLimboDocs = new HashSet<>();
915-
JSONArray limboDocs = expectedState.getJSONArray("limboDocs");
914+
if (expectedState.has("activeLimboDocs")) {
915+
expectedActiveLimboDocs = new HashSet<>();
916+
JSONArray limboDocs = expectedState.getJSONArray("activeLimboDocs");
916917
for (int i = 0; i < limboDocs.length(); i++) {
917-
expectedLimboDocs.add(key((String) limboDocs.get(i)));
918+
expectedActiveLimboDocs.add(key((String) limboDocs.get(i)));
918919
}
919920
}
920921
if (expectedState.has("activeTargets")) {
@@ -989,20 +990,28 @@ private void validateLimboDocs() {
989990
Map<DocumentKey, Integer> actualLimboDocs =
990991
new HashMap<>(syncEngine.getCurrentLimboDocuments());
991992

992-
// Validate that each limbo doc has an expected active target
993+
// Validate that each active limbo doc has an expected active target
993994
for (Map.Entry<DocumentKey, Integer> limboDoc : actualLimboDocs.entrySet()) {
994995
assertTrue(
995-
"Found limbo doc " + limboDoc.getKey() + " without an expected active target",
996+
"Found limbo doc "
997+
+ limboDoc.getKey()
998+
+ ", but its target ID "
999+
+ limboDoc.getValue()
1000+
+ " was not in the set of expected active target IDs "
1001+
+ expectedActiveTargets.keySet().stream()
1002+
.sorted()
1003+
.map(String::valueOf)
1004+
.collect(Collectors.joining(", ")),
9961005
expectedActiveTargets.containsKey(limboDoc.getValue()));
9971006
}
9981007

999-
for (DocumentKey expectedLimboDoc : expectedLimboDocs) {
1008+
for (DocumentKey expectedLimboDoc : expectedActiveLimboDocs) {
10001009
assertTrue(
10011010
"Expected doc to be in limbo, but was not: " + expectedLimboDoc,
10021011
actualLimboDocs.containsKey(expectedLimboDoc));
10031012
actualLimboDocs.remove(expectedLimboDoc);
10041013
}
1005-
assertTrue("Unexpected docs in limbo: " + actualLimboDocs, actualLimboDocs.isEmpty());
1014+
assertTrue("Unexpected active docs in limbo: " + actualLimboDocs, actualLimboDocs.isEmpty());
10061015
}
10071016

10081017
private void validateActiveTargets() {

firebase-firestore/src/test/resources/json/collection_spec_test.json

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,34 @@
22
"Events are raised after watch ack": {
33
"describeName": "Collections:",
44
"itName": "Events are raised after watch ack",
5-
"tags": [],
5+
"tags": [
6+
],
67
"config": {
7-
"useGarbageCollection": true,
8-
"numClients": 1
8+
"numClients": 1,
9+
"useGarbageCollection": true
910
},
1011
"steps": [
1112
{
1213
"userListen": [
1314
2,
1415
{
15-
"path": "collection",
16-
"filters": [],
17-
"orderBys": []
16+
"filters": [
17+
],
18+
"orderBys": [
19+
],
20+
"path": "collection"
1821
}
1922
],
2023
"expectedState": {
2124
"activeTargets": {
2225
"2": {
2326
"queries": [
2427
{
25-
"path": "collection",
26-
"filters": [],
27-
"orderBys": []
28+
"filters": [
29+
],
30+
"orderBys": [
31+
],
32+
"path": "collection"
2833
}
2934
],
3035
"resumeToken": ""
@@ -42,14 +47,14 @@
4247
"docs": [
4348
{
4449
"key": "collection/key",
45-
"version": 1000,
50+
"options": {
51+
"hasCommittedMutations": false,
52+
"hasLocalMutations": false
53+
},
4654
"value": {
4755
"foo": "bar"
4856
},
49-
"options": {
50-
"hasLocalMutations": false,
51-
"hasCommittedMutations": false
52-
}
57+
"version": 1000
5358
}
5459
],
5560
"targets": [
@@ -67,32 +72,35 @@
6772
},
6873
{
6974
"watchSnapshot": {
70-
"version": 1001,
71-
"targetIds": []
75+
"targetIds": [
76+
],
77+
"version": 1001
7278
},
7379
"expectedSnapshotEvents": [
7480
{
75-
"query": {
76-
"path": "collection",
77-
"filters": [],
78-
"orderBys": []
79-
},
8081
"added": [
8182
{
8283
"key": "collection/key",
83-
"version": 1000,
84+
"options": {
85+
"hasCommittedMutations": false,
86+
"hasLocalMutations": false
87+
},
8488
"value": {
8589
"foo": "bar"
8690
},
87-
"options": {
88-
"hasLocalMutations": false,
89-
"hasCommittedMutations": false
90-
}
91+
"version": 1000
9192
}
9293
],
9394
"errorCode": 0,
9495
"fromCache": false,
95-
"hasPendingWrites": false
96+
"hasPendingWrites": false,
97+
"query": {
98+
"filters": [
99+
],
100+
"orderBys": [
101+
],
102+
"path": "collection"
103+
}
96104
}
97105
]
98106
}
@@ -101,29 +109,34 @@
101109
"Events are raised for local sets before watch ack": {
102110
"describeName": "Collections:",
103111
"itName": "Events are raised for local sets before watch ack",
104-
"tags": [],
112+
"tags": [
113+
],
105114
"config": {
106-
"useGarbageCollection": true,
107-
"numClients": 1
115+
"numClients": 1,
116+
"useGarbageCollection": true
108117
},
109118
"steps": [
110119
{
111120
"userListen": [
112121
2,
113122
{
114-
"path": "collection",
115-
"filters": [],
116-
"orderBys": []
123+
"filters": [
124+
],
125+
"orderBys": [
126+
],
127+
"path": "collection"
117128
}
118129
],
119130
"expectedState": {
120131
"activeTargets": {
121132
"2": {
122133
"queries": [
123134
{
124-
"path": "collection",
125-
"filters": [],
126-
"orderBys": []
135+
"filters": [
136+
],
137+
"orderBys": [
138+
],
139+
"path": "collection"
127140
}
128141
],
129142
"resumeToken": ""
@@ -140,27 +153,29 @@
140153
],
141154
"expectedSnapshotEvents": [
142155
{
143-
"query": {
144-
"path": "collection",
145-
"filters": [],
146-
"orderBys": []
147-
},
148156
"added": [
149157
{
150158
"key": "collection/key",
151-
"version": 0,
159+
"options": {
160+
"hasCommittedMutations": false,
161+
"hasLocalMutations": true
162+
},
152163
"value": {
153164
"foo": "bar"
154165
},
155-
"options": {
156-
"hasLocalMutations": true,
157-
"hasCommittedMutations": false
158-
}
166+
"version": 0
159167
}
160168
],
161169
"errorCode": 0,
162170
"fromCache": true,
163-
"hasPendingWrites": true
171+
"hasPendingWrites": true,
172+
"query": {
173+
"filters": [
174+
],
175+
"orderBys": [
176+
],
177+
"path": "collection"
178+
}
164179
}
165180
]
166181
}

0 commit comments

Comments
 (0)