diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ITQueryCountTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ITQueryCountTest.java index b9e3a671e0..3d93456c87 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ITQueryCountTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ITQueryCountTest.java @@ -47,21 +47,11 @@ public class ITQueryCountTest { @Rule public TestName testName = new TestName(); - private FirestoreOptions firestoreOptions; private Firestore firestore; - @Before - public void setUpFirestoreOptions() { - firestoreOptions = FirestoreOptions.newBuilder().build(); - // TODO(count) Remove the assumeTrue() below once count queries are supported in prod. - assumeTrue( - "Count queries are only supported in the Firestore Emulator (for now)", - firestoreOptions.getHost().startsWith("localhost")); - } - @Before public void setUpFirestore() { - firestore = firestoreOptions.getService(); + firestore = FirestoreOptions.newBuilder().build().getService(); Preconditions.checkNotNull( firestore, "Error instantiating Firestore. Check that the service account credentials were properly set."); @@ -226,6 +216,11 @@ public void aggregateQueryShouldWorkInATransaction() throws Exception { @Test public void aggregateQueryInATransactionShouldLockTheCountedDocuments() throws Exception { + assumeTrue( + "Skip this test when running against production because " + + "it appears that production is failing to lock the counted documents b/248152832", + isRunningAgainstFirestoreEmulator()); + CollectionReference collection = createEmptyCollection(); DocumentReference document = createDocumentInCollection(collection); CountDownLatch aggregateQueryExecutedSignal = new CountDownLatch(1); @@ -399,6 +394,11 @@ private static void await(ApiFuture future) throws InterruptedException { executor.shutdown(); } + /** Returns whether the tests are running against the Firestore emulator. */ + private boolean isRunningAgainstFirestoreEmulator() { + return firestore.getOptions().getHost().startsWith("localhost:"); + } + @AutoValue abstract static class CreatedCollectionInfo {