Skip to content

Commit 0af81b1

Browse files
committed
Fix test against firestore emulator
1 parent f35e885 commit 0af81b1

File tree

1 file changed

+16
-12
lines changed
  • firebase-firestore/src/androidTest/java/com/google/firebase/firestore

1 file changed

+16
-12
lines changed

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import android.os.SystemClock;
3737

38+
import androidx.annotation.Nullable;
3839
import androidx.test.ext.junit.runners.AndroidJUnit4;
3940
import com.google.android.gms.tasks.Task;
4041
import com.google.common.collect.Lists;
@@ -1090,7 +1091,13 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
10901091
existenceFilterMismatchAccumulator.register();
10911092
try {
10921093
snapshot2 = waitFor(collection.get());
1093-
existenceFilterMismatchInfo = existenceFilterMismatchAccumulator.waitForExistenceFilterMismatch(/*timeoutMillis=*/5000);
1094+
// TODO(b/270731363): Remove the "if" condition below once the Firestore Emulator is fixed
1095+
// to send an existence filter.
1096+
if (isRunningAgainstEmulator()) {
1097+
existenceFilterMismatchInfo = null;
1098+
} else {
1099+
existenceFilterMismatchInfo = existenceFilterMismatchAccumulator.waitForExistenceFilterMismatch(/*timeoutMillis=*/5000);
1100+
}
10941101
} finally {
10951102
existenceFilterMismatchAccumulator.unregister();
10961103
}
@@ -1125,6 +1132,7 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
11251132

11261133
// Verify that Watch sent an existence filter with the correct counts when the query was
11271134
// resumed.
1135+
assertWithMessage("Watch should have sent an existence filter").that(existenceFilterMismatchInfo).isNotNull();
11281136
assertWithMessage("localCacheCount").that(existenceFilterMismatchInfo.localCacheCount()).isEqualTo(100);
11291137
assertWithMessage("existenceFilterCount").that(existenceFilterMismatchInfo.existenceFilterCount()).isEqualTo(50);
11301138
}
@@ -1150,6 +1158,7 @@ void unregister() {
11501158
listenerRegistration = null;
11511159
}
11521160

1161+
@Nullable
11531162
WatchChangeAggregatorTestingHooksAccessor.ExistenceFilterMismatchInfo waitForExistenceFilterMismatch(long timeoutMillis) throws InterruptedException {
11541163
if (listenerRegistration == null) {
11551164
throw new IllegalStateException("must be registered before waiting for an existence filter mismatch");
@@ -1163,36 +1172,31 @@ private final class ExistenceFilterMismatchListenerImpl implements WatchChangeAg
11631172

11641173
@Override
11651174
public void onExistenceFilterMismatch(WatchChangeAggregatorTestingHooksAccessor.ExistenceFilterMismatchInfo info) {
1166-
synchronized (existenceFilterMismatchesLock) {
1175+
synchronized (existenceFilterMismatches) {
11671176
existenceFilterMismatches.add(info);
1168-
existenceFilterMismatchesLock.notifyAll();
1177+
existenceFilterMismatches.notifyAll();
11691178
}
11701179
}
11711180

1181+
@Nullable
11721182
WatchChangeAggregatorTestingHooksAccessor.ExistenceFilterMismatchInfo waitForExistenceFilterMismatch(long timeoutMillis) throws InterruptedException {
11731183
if (timeoutMillis <= 0) {
11741184
throw new IllegalArgumentException("invalid timeout: " + timeoutMillis);
11751185
}
1176-
synchronized (existenceFilterMismatchesLock) {
1186+
synchronized (existenceFilterMismatches) {
11771187
long endTimeMillis = SystemClock.uptimeMillis() + timeoutMillis;
11781188
while (true) {
11791189
if (existenceFilterMismatches.size() > 0) {
11801190
return existenceFilterMismatches.remove(0);
11811191
}
11821192
long currentWaitMillis = endTimeMillis - SystemClock.uptimeMillis();
11831193
if (currentWaitMillis <= 0) {
1184-
throw new WaitForExistenceFilterMismatchTimeoutException("timeout (" + timeoutMillis + "ms) waiting for an existence filter mismatch");
1194+
return null;
11851195
}
1186-
existenceFilterMismatchesLock.wait(currentWaitMillis);
1196+
existenceFilterMismatches.wait(currentWaitMillis);
11871197
}
11881198
}
11891199
}
1190-
1191-
final class WaitForExistenceFilterMismatchTimeoutException extends RuntimeException {
1192-
WaitForExistenceFilterMismatchTimeoutException(String message) {
1193-
super(message);
1194-
}
1195-
}
11961200
}
11971201

11981202
}

0 commit comments

Comments
 (0)