Skip to content

Firestore: Add test that verifies count query error message when missing index #4232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.firebase.firestore;

import static com.google.common.truth.Truth.assertThat;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
Expand All @@ -25,10 +26,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
import java.util.Collections;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -253,4 +258,23 @@ public void testFailWithoutNetwork() {
AggregateQuerySnapshot snapshot = waitFor(collection.count().get(AggregateSource.SERVER));
assertEquals(3L, snapshot.getCount());
}

@Test
public void testFailWithGoodMessageIfMissingIndex() {
assumeFalse(
"Skip this test when running against the Firestore emulator because the Firestore emulator "
+ "does not use indexes and never fails with a 'missing index' error",
BuildConfig.USE_EMULATOR_FOR_TESTS);

CollectionReference collection = testCollectionWithDocs(Collections.emptyMap());
Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99);
AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count();
Task<AggregateQuerySnapshot> task = compositeIndexCountQuery.get(AggregateSource.SERVER);

Throwable throwable = assertThrows(Throwable.class, () -> waitFor(task));

Throwable cause = throwable.getCause();
assertThat(cause).hasMessageThat().ignoringCase().contains("index");
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
}
}