Skip to content

Setup CI for named db tests #5206

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 9 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
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
41 changes: 41 additions & 0 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,47 @@ jobs:
run: |
./gradlew ${{matrix.module}}:deviceCheck withErrorProne -PtargetBackend="prod"

firestore_custom_integ_tests:
name: "Firestore Custom Instrumentation Tests Against Named DB"
runs-on: ubuntu-22.04
needs:
- determine_changed
# only run on post submit or PRs not originating from forks.
if: ((github.repository == 'Firebase/firebase-android-sdk' && github.event_name == 'push') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)) && contains(fromJSON(needs.determine_changed.outputs.modules), ':firebase-firestore')
strategy:
fail-fast: false

steps:
- uses: actions/[email protected]
with:
fetch-depth: 2
submodules: true

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
cache: gradle

- name: Add google-services.json
env:
INTEG_TESTS_GOOGLE_SERVICES: ${{ secrets.INTEG_TESTS_GOOGLE_SERVICES }}
run: |
echo $INTEG_TESTS_GOOGLE_SERVICES | base64 -d > google-services.json
- uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- uses: google-github-actions/setup-gcloud@v0
- name: Firestore Named DB Integ Tests
env:
FIREBASE_CI: 1
FTL_RESULTS_BUCKET: android-ci
FTL_RESULTS_DIR: ${{ github.event_name == 'pull_request' && format('pr-logs/pull/{0}/{1}/{2}/{3}_{4}/artifacts/', github.repository, github.event.pull_request.number, github.job, github.run_id, github.run_attempt) || format('logs/{0}/{1}_{2}/artifacts/', github.workflow, github.run_id, github.run_attempt)}}
FIREBASE_APP_CHECK_DEBUG_SECRET: ${{ secrets.FIREBASE_APP_CHECK_DEBUG_SECRET }}
run: |
./gradlew firebase-firestore:deviceCheck withErrorProne -PtargetBackend="prod" -PtargetDatabaseId="test-db"

publish-test-results:
name: "Publish Tests Results"
needs:
Expand Down
5 changes: 4 additions & 1 deletion firebase-firestore/firebase-firestore.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ android {
def targetBackend = findProperty("targetBackend") ?: "emulator"
buildConfigField("String", "TARGET_BACKEND", "\"$targetBackend\"")

def targetDatabaseId = findProperty('targetDatabaseId') ?: "(default)"
buildConfigField("String", "TARGET_DATABASE_ID", "\"$targetDatabaseId\"")

def localProps = new Properties()

try {
Expand Down Expand Up @@ -154,7 +157,7 @@ dependencies {
testImplementation 'com.google.guava:guava-testlib:12.0-rc2'

androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation("com.google.truth:truth:$googleTruthVersion"){
androidTestImplementation("com.google.truth:truth:$googleTruthVersion") {
exclude group: "org.codehaus.mojo", module: "animal-sniffer-annotations"
}
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
Expand Down
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.querySnapshotToValues;
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
import static com.google.firebase.firestore.testutil.TestUtil.map;
Expand Down Expand Up @@ -198,7 +199,7 @@ public void testLoadedDocumentsShouldNotBeGarbageCollectedRightAway() throws Exc
public void testLoadWithDocumentsFromOtherProjectFails() throws Exception {
List<LoadBundleTaskProgress> progressEvents = new ArrayList<>();

byte[] bundle = createBundle("other-project");
byte[] bundle = createBundle("other-project", db.getDatabaseId().getDatabaseId());
LoadBundleTask bundleTask = db.loadBundle(bundle);

bundleTask.addOnProgressListener(progressEvents::add);
Expand All @@ -207,10 +208,9 @@ public void testLoadWithDocumentsFromOtherProjectFails() throws Exception {
awaitCompletion(bundleTask);
fail();
} catch (RuntimeExecutionException e) {
assertEquals(
"Resource name is not valid for current instance: "
+ "projects/other-project/databases/(default)/documents",
e.getCause().getCause().getMessage());
assertThat(e.getCause().getCause())
.hasMessageThat()
.contains("Resource name is not valid for current instance");
}

assertEquals(2, progressEvents.size());
Expand Down Expand Up @@ -262,14 +262,16 @@ private int getUTF8ByteCount(String s) {
* Returns a valid bundle by replacing project id in `BUNDLE_TEMPLATES` with the given db project
* id (also recalculates length prefixes).
*/
private byte[] createBundle(String projectId) throws UnsupportedEncodingException {
private byte[] createBundle(String projectId, String databaseId)
throws UnsupportedEncodingException {
StringBuilder bundle = new StringBuilder();

// Prepare non-metadata elements since we need the total length of these elements before
// generating the metadata.
for (int i = 1; i < BUNDLE_TEMPLATES.length; ++i) {
// Extract elements from BUNDLE_TEMPLATE and replace the project ID.
String element = BUNDLE_TEMPLATES[i].replaceAll("\\{projectId\\}", projectId);
element = element.replaceAll("\\(default\\)", databaseId);
bundle.append(getUTF8ByteCount(element));
bundle.append(element);
}
Expand All @@ -290,7 +292,7 @@ private byte[] createBundle(String projectId) throws UnsupportedEncodingExceptio
* current test database.
*/
private byte[] createBundle() throws UnsupportedEncodingException {
return createBundle(db.getDatabaseId().getProjectId());
return createBundle(db.getDatabaseId().getProjectId(), db.getDatabaseId().getDatabaseId());
}

private void verifySuccessProgress(LoadBundleTaskProgress progress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.model.DatabaseId;
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
import java.util.Collections;
import org.junit.After;
Expand Down Expand Up @@ -276,6 +277,14 @@ public void testCountFailWithGoodMessageIfMissingIndex() {

Throwable cause = throwable.getCause();
assertThat(cause).hasMessageThat().ignoringCase().contains("index");
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
if (collection
.firestore
.getDatabaseId()
.getDatabaseId()
.equals(DatabaseId.DEFAULT_DATABASE_ID)) {
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
} else {
assertThat(cause).hasMessageThat().contains("Missing index configuration");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void firestoreGetInstanceWithNullAppFails() {
}

@Test
public void firestoreGetInstanceWithNullDbNamepFails() {
public void firestoreGetInstanceWithNullDbNameFails() {
FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext());
expectError(
() -> FirebaseFirestore.getInstance((String) null),
"Provided database name must not be null.");
Expand Down Expand Up @@ -248,9 +249,12 @@ public void writesMustNotContainReferencesToADifferentDatabase() {
expectWriteError(
data,
String.format(
"Invalid data. Document reference is for database %s/(default) but should be for "
+ "database %s/(default) (found in field foo)",
IntegrationTestUtil.BAD_PROJECT_ID, IntegrationTestUtil.provider().projectId()));
"Invalid data. Document reference is for database %s/%s but should be for "
+ "database %s/%s (found in field foo)",
IntegrationTestUtil.BAD_PROJECT_ID,
BuildConfig.TARGET_DATABASE_ID,
IntegrationTestUtil.provider().projectId(),
BuildConfig.TARGET_DATABASE_ID));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public static FirebaseFirestore testFirestore(
FirebaseFirestoreSettings settings,
String persistenceKey) {
return testFirestore(
DatabaseId.forDatabase(projectId, DatabaseId.DEFAULT_DATABASE_ID),
DatabaseId.forDatabase(projectId, BuildConfig.TARGET_DATABASE_ID),
logLevel,
settings,
persistenceKey);
Expand Down