Skip to content

Commit 8ce2dfc

Browse files
authored
Setup CI for named db tests (#5206)
* Initial setup * fix gradle file * separate job * Control * Address Feedback.
1 parent 622d65b commit 8ce2dfc

File tree

6 files changed

+73
-14
lines changed

6 files changed

+73
-14
lines changed

.github/workflows/ci_tests.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,47 @@ jobs:
130130
run: |
131131
./gradlew ${{matrix.module}}:deviceCheck withErrorProne -PtargetBackend="prod"
132132
133+
firestore_custom_integ_tests:
134+
name: "Firestore Custom Instrumentation Tests Against Named DB"
135+
runs-on: ubuntu-22.04
136+
needs:
137+
- determine_changed
138+
# only run on post submit or PRs not originating from forks.
139+
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')
140+
strategy:
141+
fail-fast: false
142+
143+
steps:
144+
- uses: actions/[email protected]
145+
with:
146+
fetch-depth: 2
147+
submodules: true
148+
149+
- name: Set up JDK 11
150+
uses: actions/setup-java@v3
151+
with:
152+
java-version: 11
153+
distribution: temurin
154+
cache: gradle
155+
156+
- name: Add google-services.json
157+
env:
158+
INTEG_TESTS_GOOGLE_SERVICES: ${{ secrets.INTEG_TESTS_GOOGLE_SERVICES }}
159+
run: |
160+
echo $INTEG_TESTS_GOOGLE_SERVICES | base64 -d > google-services.json
161+
- uses: google-github-actions/auth@v0
162+
with:
163+
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT }}
164+
- uses: google-github-actions/setup-gcloud@v0
165+
- name: Firestore Named DB Integ Tests
166+
env:
167+
FIREBASE_CI: 1
168+
FTL_RESULTS_BUCKET: android-ci
169+
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)}}
170+
FIREBASE_APP_CHECK_DEBUG_SECRET: ${{ secrets.FIREBASE_APP_CHECK_DEBUG_SECRET }}
171+
run: |
172+
./gradlew firebase-firestore:deviceCheck withErrorProne -PtargetBackend="prod" -PtargetDatabaseId="test-db"
173+
133174
publish-test-results:
134175
name: "Publish Tests Results"
135176
needs:

firebase-firestore/firebase-firestore.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ android {
7070
def targetBackend = findProperty("targetBackend") ?: "emulator"
7171
buildConfigField("String", "TARGET_BACKEND", "\"$targetBackend\"")
7272

73+
def targetDatabaseId = findProperty('targetDatabaseId') ?: "(default)"
74+
buildConfigField("String", "TARGET_DATABASE_ID", "\"$targetDatabaseId\"")
75+
7376
def localProps = new Properties()
7477

7578
try {
@@ -154,7 +157,7 @@ dependencies {
154157
testImplementation 'com.google.guava:guava-testlib:12.0-rc2'
155158

156159
androidTestImplementation 'junit:junit:4.13.2'
157-
androidTestImplementation("com.google.truth:truth:$googleTruthVersion"){
160+
androidTestImplementation("com.google.truth:truth:$googleTruthVersion") {
158161
exclude group: "org.codehaus.mojo", module: "animal-sniffer-annotations"
159162
}
160163
androidTestImplementation 'org.mockito:mockito-core:2.25.0'

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

Lines changed: 9 additions & 7 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.common.truth.Truth.assertThat;
1718
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToValues;
1819
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
1920
import static com.google.firebase.firestore.testutil.TestUtil.map;
@@ -198,7 +199,7 @@ public void testLoadedDocumentsShouldNotBeGarbageCollectedRightAway() throws Exc
198199
public void testLoadWithDocumentsFromOtherProjectFails() throws Exception {
199200
List<LoadBundleTaskProgress> progressEvents = new ArrayList<>();
200201

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

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

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

268269
// Prepare non-metadata elements since we need the total length of these elements before
269270
// generating the metadata.
270271
for (int i = 1; i < BUNDLE_TEMPLATES.length; ++i) {
271272
// Extract elements from BUNDLE_TEMPLATE and replace the project ID.
272273
String element = BUNDLE_TEMPLATES[i].replaceAll("\\{projectId\\}", projectId);
274+
element = element.replaceAll("\\(default\\)", databaseId);
273275
bundle.append(getUTF8ByteCount(element));
274276
bundle.append(element);
275277
}
@@ -290,7 +292,7 @@ private byte[] createBundle(String projectId) throws UnsupportedEncodingExceptio
290292
* current test database.
291293
*/
292294
private byte[] createBundle() throws UnsupportedEncodingException {
293-
return createBundle(db.getDatabaseId().getProjectId());
295+
return createBundle(db.getDatabaseId().getProjectId(), db.getDatabaseId().getDatabaseId());
294296
}
295297

296298
private void verifySuccessProgress(LoadBundleTaskProgress progress) {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

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

277278
Throwable cause = throwable.getCause();
278279
assertThat(cause).hasMessageThat().ignoringCase().contains("index");
279-
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
280+
if (collection
281+
.firestore
282+
.getDatabaseId()
283+
.getDatabaseId()
284+
.equals(DatabaseId.DEFAULT_DATABASE_ID)) {
285+
assertThat(cause).hasMessageThat().contains("https://console.firebase.google.com");
286+
} else {
287+
assertThat(cause).hasMessageThat().contains("Missing index configuration");
288+
}
280289
}
281290
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public void firestoreGetInstanceWithNullAppFails() {
100100
}
101101

102102
@Test
103-
public void firestoreGetInstanceWithNullDbNamepFails() {
103+
public void firestoreGetInstanceWithNullDbNameFails() {
104+
FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext());
104105
expectError(
105106
() -> FirebaseFirestore.getInstance((String) null),
106107
"Provided database name must not be null.");
@@ -248,9 +249,12 @@ public void writesMustNotContainReferencesToADifferentDatabase() {
248249
expectWriteError(
249250
data,
250251
String.format(
251-
"Invalid data. Document reference is for database %s/(default) but should be for "
252-
+ "database %s/(default) (found in field foo)",
253-
IntegrationTestUtil.BAD_PROJECT_ID, IntegrationTestUtil.provider().projectId()));
252+
"Invalid data. Document reference is for database %s/%s but should be for "
253+
+ "database %s/%s (found in field foo)",
254+
IntegrationTestUtil.BAD_PROJECT_ID,
255+
BuildConfig.TARGET_DATABASE_ID,
256+
IntegrationTestUtil.provider().projectId(),
257+
BuildConfig.TARGET_DATABASE_ID));
254258
}
255259

256260
@Test

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/testutil/IntegrationTestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public static FirebaseFirestore testFirestore(
283283
FirebaseFirestoreSettings settings,
284284
String persistenceKey) {
285285
return testFirestore(
286-
DatabaseId.forDatabase(projectId, DatabaseId.DEFAULT_DATABASE_ID),
286+
DatabaseId.forDatabase(projectId, BuildConfig.TARGET_DATABASE_ID),
287287
logLevel,
288288
settings,
289289
persistenceKey);

0 commit comments

Comments
 (0)