Skip to content

Commit 10f0c8e

Browse files
Fix unit tests
1 parent 805f41e commit 10f0c8e

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ private void notifyLocalViewChanges(LocalViewChanges changes) {
146146
localStore.notifyLocalViewChanges(asList(changes));
147147
}
148148

149-
private void udpateViews(int targetId) {
150-
notifyLocalViewChanges(viewChanges(targetId, asList(), asList()));
149+
private void udpateViews(int targetId, boolean synced) {
150+
notifyLocalViewChanges(viewChanges(targetId, synced, asList(), asList()));
151151
}
152152

153153
private void acknowledgeMutation(long documentVersion, @Nullable Object transformResult) {
@@ -311,7 +311,7 @@ public void testHandlesSetMutationThenAckThenRelease() {
311311
allocateQuery(query);
312312

313313
writeMutation(setMutation("foo/bar", map("foo", "bar")));
314-
notifyLocalViewChanges(viewChanges(2, asList("foo/bar"), emptyList()));
314+
notifyLocalViewChanges(viewChanges(2, /* synced= */ false, asList("foo/bar"), emptyList()));
315315

316316
assertChanged(doc("foo/bar", 0, map("foo", "bar"), Document.DocumentState.LOCAL_MUTATIONS));
317317
assertContains(doc("foo/bar", 0, map("foo", "bar"), Document.DocumentState.LOCAL_MUTATIONS));
@@ -831,14 +831,16 @@ public void testPinsDocumentsInTheLocalView() {
831831
assertContains(doc("foo/bar", 1, map("foo", "bar")));
832832
assertContains(doc("foo/baz", 0, map("foo", "baz"), Document.DocumentState.LOCAL_MUTATIONS));
833833

834-
notifyLocalViewChanges(viewChanges(2, asList("foo/bar", "foo/baz"), emptyList()));
834+
notifyLocalViewChanges(
835+
viewChanges(2, /* synced= */ false, asList("foo/bar", "foo/baz"), emptyList()));
835836
applyRemoteEvent(updateRemoteEvent(doc("foo/bar", 1, map("foo", "bar")), none, two));
836837
applyRemoteEvent(updateRemoteEvent(doc("foo/baz", 2, map("foo", "baz")), two, none));
837838
acknowledgeMutation(2);
838839
assertContains(doc("foo/bar", 1, map("foo", "bar")));
839840
assertContains(doc("foo/baz", 2, map("foo", "baz")));
840841

841-
notifyLocalViewChanges(viewChanges(2, emptyList(), asList("foo/bar", "foo/baz")));
842+
notifyLocalViewChanges(
843+
viewChanges(2, /* synced= */ false, emptyList(), asList("foo/bar", "foo/baz")));
842844
releaseQuery(query);
843845

844846
assertNotContains("foo/bar");
@@ -1057,7 +1059,7 @@ public void testUsesTargetMappingToExecuteQueries() {
10571059
asList(targetId),
10581060
emptyList()));
10591061
applyRemoteEvent(noChangeEvent(targetId, 10));
1060-
udpateViews(targetId);
1062+
udpateViews(targetId, /* synced= */ true);
10611063

10621064
// Execute the query again, this time verifying that we only read the two documents that match
10631065
// the query.
@@ -1092,9 +1094,14 @@ public void testLastLimboFreeSnapshotIsAdvancedDuringViewProcessing() {
10921094
// At this point, we have not yet confirmed that the query is limbo free.
10931095
Assert.assertEquals(
10941096
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
1095-
udpateViews(targetId);
10961097

1097-
// The query is marked limbo-free during the view computation.
1098+
// Update the view, but don't mark the view synced.
1099+
Assert.assertEquals(
1100+
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
1101+
udpateViews(targetId, /* synced=*/ true);
1102+
1103+
// The query is marked limbo-free only when we mark the view synced.
1104+
udpateViews(targetId, /* synced=*/ true);
10981105
Assert.assertNotEquals(
10991106
SnapshotVersion.NONE, localStore.getQueryData(query).getLastLimboFreeSnapshotVersion());
11001107

@@ -1124,7 +1131,7 @@ public void testQueriesIncludeLocallyModifiedDocuments() {
11241131
asList(targetId),
11251132
emptyList()));
11261133
applyRemoteEvent(noChangeEvent(targetId, 10));
1127-
udpateViews(targetId);
1134+
udpateViews(targetId, /* synced= */ true);
11281135

11291136
// Execute the query based on the RemoteEvent.
11301137
executeQuery(query);
@@ -1161,7 +1168,7 @@ public void testQueriesIncludeDocumentsFromOtherQueries() {
11611168
asList(targetId),
11621169
emptyList()));
11631170
applyRemoteEvent(noChangeEvent(targetId, 10));
1164-
udpateViews(targetId);
1171+
udpateViews(targetId, /* synced=*/ true);
11651172
releaseQuery(filteredQuery);
11661173

11671174
// Start another query and add more matching documents to the collection.
@@ -1203,7 +1210,7 @@ public void testQueriesFilterDocumentsThatNoLongerMatch() {
12031210
asList(targetId),
12041211
emptyList()));
12051212
applyRemoteEvent(noChangeEvent(targetId, 10));
1206-
udpateViews(targetId);
1213+
udpateViews(targetId, /* synced=*/ true);
12071214
releaseQuery(filteredQuery);
12081215

12091216
// Modify one of the documents to no longer match while the filtered query is inactive.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public static MutationResult mutationResult(long version) {
523523
}
524524

525525
public static LocalViewChanges viewChanges(
526-
int targetId, List<String> addedKeys, List<String> removedKeys) {
526+
int targetId, boolean synced, List<String> addedKeys, List<String> removedKeys) {
527527
ImmutableSortedSet<DocumentKey> added = DocumentKey.emptyKeySet();
528528
for (String keyPath : addedKeys) {
529529
added = added.insert(key(keyPath));
@@ -532,7 +532,7 @@ public static LocalViewChanges viewChanges(
532532
for (String keyPath : removedKeys) {
533533
removed = removed.insert(key(keyPath));
534534
}
535-
return new LocalViewChanges(targetId, false, added, removed);
535+
return new LocalViewChanges(targetId, synced, added, removed);
536536
}
537537

538538
/** Creates a resume token to match the given snapshot version. */

0 commit comments

Comments
 (0)