Skip to content

Commit 649f22d

Browse files
Revert "Simplify IndexFree tests (#790)"
This reverts commit a011927.
1 parent 6571c9c commit 649f22d

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,31 +1073,49 @@ public void testUsesTargetMappingToExecuteQueries() {
10731073

10741074
@Test
10751075
public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing() {
1076+
assumeFalse(garbageCollectorIsEager());
1077+
assumeTrue(queryEngine instanceof IndexFreeQueryEngine);
1078+
10761079
// This test verifies that the `lastLimboFreeSnapshot` version for QueryData is advanced when
10771080
// we compute a limbo-free free view and that the mapping is persisted when we release a query.
10781081

1079-
Query query = Query.atPath(ResourcePath.fromString("foo"));
1082+
writeMutation(setMutation("foo/ignored", map("matches", false)));
1083+
acknowledgeMutation(10);
1084+
1085+
Query query =
1086+
Query.atPath(ResourcePath.fromString("foo")).filter(filter("matches", "==", true));
10801087
int targetId = allocateQuery(query);
10811088

1082-
// Advance the query snapshot.
1089+
// Mark the query as current.
1090+
applyRemoteEvent(
1091+
addedRemoteEvent(
1092+
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 10, map("matches", true))),
1093+
asList(targetId),
1094+
emptyList()));
10831095
applyRemoteEvent(noChangeEvent(targetId, 10));
10841096

10851097
// At this point, we have not yet confirmed that the query is limbo free.
1086-
QueryData cachedQueryData = localStore.getQueryData(query);
1087-
Assert.assertEquals(SnapshotVersion.NONE, cachedQueryData.getLastLimboFreeSnapshotVersion());
1098+
Assert.assertEquals(
1099+
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
10881100

1089-
// Mark the view synced, which updates the last limbo free snapshot version.
1101+
// Update the view, but don't mark the view synced.
1102+
Assert.assertEquals(
1103+
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
10901104
udpateViews(targetId, /* fromCache=*/ false);
1091-
cachedQueryData = localStore.getQueryData(query);
1092-
Assert.assertEquals(version(10), cachedQueryData.getLastLimboFreeSnapshotVersion());
1105+
1106+
// The query is marked limbo-free only when we mark the view synced.
1107+
udpateViews(targetId, /* fromCache=*/ false);
1108+
Assert.assertNotEquals(
1109+
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
10931110

10941111
// The last limbo free snapshot version is persisted even if we release the query.
10951112
releaseQuery(query);
1113+
allocateQuery(query);
10961114

1097-
if (!garbageCollectorIsEager()) {
1098-
cachedQueryData = localStore.getQueryData(query);
1099-
Assert.assertEquals(version(10), cachedQueryData.getLastLimboFreeSnapshotVersion());
1100-
}
1115+
// Verify that we only read the two documents that match the query.
1116+
executeQuery(query);
1117+
assertRemoteDocumentsRead(2);
1118+
assertQueryReturned("foo/a", "foo/b");
11011119
}
11021120

11031121
@Test
@@ -1112,26 +1130,28 @@ public void testQueriesIncludeLocallyModifiedDocuments() {
11121130

11131131
applyRemoteEvent(
11141132
addedRemoteEvent(
1115-
asList(doc("foo/a", 10, map("matches", true))), asList(targetId), emptyList()));
1133+
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 10, map("matches", true))),
1134+
asList(targetId),
1135+
emptyList()));
11161136
applyRemoteEvent(noChangeEvent(targetId, 10));
11171137
udpateViews(targetId, /* fromCache= */ false);
11181138

11191139
// Execute the query based on the RemoteEvent.
11201140
executeQuery(query);
1121-
assertQueryReturned("foo/a");
1141+
assertQueryReturned("foo/a", "foo/b");
11221142

11231143
// Write a document.
1124-
writeMutation(setMutation("foo/b", map("matches", true)));
1144+
writeMutation(setMutation("foo/c", map("matches", true)));
11251145

11261146
// Execute the query and make sure that the pending mutation is included in the result.
11271147
executeQuery(query);
1128-
assertQueryReturned("foo/a", "foo/b");
1148+
assertQueryReturned("foo/a", "foo/b", "foo/c");
11291149

11301150
acknowledgeMutation(11);
11311151

11321152
// Execute the query and make sure that the acknowledged mutation is included in the result.
11331153
executeQuery(query);
1134-
assertQueryReturned("foo/a", "foo/b");
1154+
assertQueryReturned("foo/a", "foo/b", "foo/c");
11351155
}
11361156

11371157
@Test
@@ -1147,17 +1167,23 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
11471167

11481168
applyRemoteEvent(
11491169
addedRemoteEvent(
1150-
asList(doc("foo/a", 10, map("matches", true))), asList(targetId), emptyList()));
1170+
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 10, map("matches", true))),
1171+
asList(targetId),
1172+
emptyList()));
11511173
applyRemoteEvent(noChangeEvent(targetId, 10));
11521174
udpateViews(targetId, /* fromCache=*/ false);
11531175
releaseQuery(filteredQuery);
11541176

11551177
// Start another query and add more matching documents to the collection.
1156-
Query fullQuery = Query.atPath(ResourcePath.fromString("foo"));
1157-
targetId = allocateQuery(fullQuery);
1178+
Query fullQuery =
1179+
Query.atPath(ResourcePath.fromString("foo")).filter(filter("matches", "==", true));
1180+
targetId = allocateQuery(filteredQuery);
11581181
applyRemoteEvent(
11591182
addedRemoteEvent(
1160-
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 20, map("matches", true))),
1183+
asList(
1184+
doc("foo/a", 10, map("matches", true)),
1185+
doc("foo/b", 10, map("matches", true)),
1186+
doc("foo/c", 20, map("matches", true))),
11611187
asList(targetId),
11621188
emptyList()));
11631189
releaseQuery(fullQuery);
@@ -1166,7 +1192,7 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
11661192
// matches are included in the result set.
11671193
allocateQuery(filteredQuery);
11681194
executeQuery(filteredQuery);
1169-
assertQueryReturned("foo/a", "foo/b");
1195+
assertQueryReturned("foo/a", "foo/b", "foo/c");
11701196
}
11711197

11721198
@Test
@@ -1191,8 +1217,9 @@ public void testQueriesFilterDocumentsThatNoLongerMatch() {
11911217
releaseQuery(filteredQuery);
11921218

11931219
// Modify one of the documents to no longer match while the filtered query is inactive.
1194-
Query fullQuery = Query.atPath(ResourcePath.fromString("foo"));
1195-
targetId = allocateQuery(fullQuery);
1220+
Query fullQuery =
1221+
Query.atPath(ResourcePath.fromString("foo")).filter(filter("matches", "==", true));
1222+
targetId = allocateQuery(filteredQuery);
11961223
applyRemoteEvent(
11971224
addedRemoteEvent(
11981225
asList(doc("foo/a", 10, map("matches", true)), doc("foo/b", 20, map("matches", false))),

firebase-firestore/src/testUtil/java/com/google/firebase/firestore/testutil/TestUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,13 @@ public QueryData getQueryDataForTarget(int targetId) {
418418
}
419419
});
420420

421-
SnapshotVersion version = SnapshotVersion.NONE;
422-
423421
for (MaybeDocument doc : docs) {
424422
DocumentChange change =
425423
new DocumentChange(updatedInTargets, removedFromTargets, doc.getKey(), doc);
426424
aggregator.handleDocumentChange(change);
427-
version = doc.getVersion().compareTo(version) > 0 ? doc.getVersion() : version;
428425
}
429426

427+
SnapshotVersion version = docs.get(0).getVersion();
430428
return aggregator.createRemoteEvent(version);
431429
}
432430

0 commit comments

Comments
 (0)