Skip to content

Commit a2c8eb0

Browse files
authored
Merge a6947ca into 9e7023d
2 parents 9e7023d + a6947ca commit a2c8eb0

File tree

1 file changed

+43
-0
lines changed
  • firebase-firestore/src/androidTest/java/com/google/firebase/firestore

1 file changed

+43
-0
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/QueryTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.firebase.firestore;
1616

17+
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.isRunningAgainstEmulator;
1718
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.nullList;
1819
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToIds;
1920
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToValues;
@@ -29,6 +30,7 @@
2930
import static org.junit.Assert.assertFalse;
3031
import static org.junit.Assert.assertNull;
3132
import static org.junit.Assert.assertTrue;
33+
import static org.junit.Assume.assumeFalse;
3234

3335
import androidx.test.ext.junit.runners.AndroidJUnit4;
3436
import com.google.android.gms.tasks.Task;
@@ -37,6 +39,7 @@
3739
import com.google.firebase.firestore.testutil.EventAccumulator;
3840
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
3941
import java.util.ArrayList;
42+
import java.util.HashMap;
4043
import java.util.LinkedHashMap;
4144
import java.util.List;
4245
import java.util.Map;
@@ -1029,6 +1032,46 @@ public void testMultipleUpdatesWhileOffline() {
10291032
assertEquals(asList(map("foo", "zzyzx", "bar", "2")), querySnapshotToValues(snapshot2));
10301033
}
10311034

1035+
@Test
1036+
public void resumingQueryShouldRemoveDeletedDocumentsIndicatedByExistenceFilter()
1037+
throws InterruptedException {
1038+
assumeFalse(
1039+
"Skip this test when running against the Firestore emulator as there is a bug related to "
1040+
+ "sending existence filter in response: b/270731363.",
1041+
isRunningAgainstEmulator());
1042+
1043+
Map<String, Map<String, Object>> testData = new HashMap<>();
1044+
for (int i = 1; i <= 100; i++) {
1045+
testData.put("doc" + i, map("key", i));
1046+
}
1047+
CollectionReference collection = testCollectionWithDocs(testData);
1048+
1049+
// Populate the cache and save the resume token.
1050+
QuerySnapshot snapshot1 = waitFor(collection.get());
1051+
assertEquals(snapshot1.size(), 100);
1052+
List<DocumentSnapshot> documents = snapshot1.getDocuments();
1053+
1054+
// Delete 50 docs in transaction so that it doesn't affect local cache.
1055+
waitFor(
1056+
collection
1057+
.getFirestore()
1058+
.runTransaction(
1059+
transaction -> {
1060+
for (int i = 1; i <= 50; i++) {
1061+
DocumentReference docRef = documents.get(i).getReference();
1062+
transaction.delete(docRef);
1063+
}
1064+
return null;
1065+
}));
1066+
1067+
// Wait 10 seconds, during which Watch will stop tracking the query
1068+
// and will send an existence filter rather than "delete" events.
1069+
Thread.sleep(10000);
1070+
1071+
QuerySnapshot snapshot2 = waitFor(collection.get());
1072+
assertEquals(snapshot2.size(), 50);
1073+
}
1074+
10321075
// TODO(orquery): Enable this test when prod supports OR queries.
10331076
@Ignore
10341077
@Test

0 commit comments

Comments
 (0)