Skip to content
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

dataconnect: GrpcMetadataIntegrationTest.kt: Fix race condition waiting for auth/appcheck to be ready #6446

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Nov 8, 2024

This PR fixes a race condition in GrpcMetadataIntegrationTest.kt where the query/mutation may be sent before the Auth and/or AppCheck provider was registered, which is done asynchronously. This race condition resulted in flaky tests. We may want to expose this functionality to customers if they run into similar issues.

For the record, the test case failures look like this:

failed: executeQueryShouldSendAppCheckMetadataWhenAppCheckIsEnabled(com.google.firebase.dataconnect.GrpcMetadataIntegrationTest)
java.lang.AssertionError: key=Key{name='x-firebase-appcheck'}, metadata=Metadata(user-agent=grpc-java-okhttp/1.62.2,content-type=application/grpc,te=trailers,x-goog-request-params=location=TestLocationr24xs74t3s&frontend=data,x-goog-api-client=gl-kotlin/1.8.22 gl-android/35 fire/16.0.0-beta03 grpc/,x-firebase-gmpid=1:12345678901:android:1234567890abcdef123456,grpc-accept-encoding=gzip)
Expected "7gwvj8c4xy" but actual was null
 	at com.google.firebase.dataconnect.GrpcMetadataIntegrationTest.verifyMetadataContains(GrpcMetadataIntegrationTest.kt:292)

failed: executeMutationShouldSendAuthMetadataWhenLoggedIn(com.google.firebase.dataconnect.GrpcMetadataIntegrationTest)
java.lang.AssertionError: key=Key{name='x-firebase-auth-token'}, metadata=Metadata(user-agent=grpc-java-okhttp/1.62.2,content-type=application/grpc,te=trailers,x-goog-request-params=location=TestLocationxbjfp54tnt&frontend=data,x-goog-api-client=gl-kotlin/1.8.22 gl-android/35 fire/16.0.0-beta03 grpc/,x-firebase-gmpid=1:12345678901:android:1234567890abcdef123456,x-firebase-appcheck=eyJlcnJvciI6IlVOS05PV05fRVJST1IifQ==,grpc-accept-encoding=gzip)
Expected value to not be null, but was null.
	at com.google.firebase.dataconnect.GrpcMetadataIntegrationTest.verifyMetadataContains(GrpcMetadataIntegrationTest.kt:290)

failed: executeQueryShouldNotSendAuthMetadataAfterLogout(com.google.firebase.dataconnect.GrpcMetadataIntegrationTest)
java.lang.AssertionError: key=Key{name='x-firebase-auth-token'}, metadata=Metadata(user-agent=grpc-java-okhttp/1.62.2,content-type=application/grpc,te=trailers,x-goog-request-params=location=TestLocationjf5zs743ev&frontend=data,x-goog-api-client=gl-kotlin/1.8.22 gl-android/35 fire/16.0.0-beta03 grpc/,x-firebase-gmpid=1:12345678901:android:1234567890abcdef123456,grpc-accept-encoding=gzip)
Expected value to not be null, but was null.
	at com.google.firebase.dataconnect.GrpcMetadataIntegrationTest.verifyMetadataContains(GrpcMetadataIntegrationTest.kt:290)

Note: This PR introduced a race condition that was fixed a few commits later in #6448

Copy link
Contributor

github-actions bot commented Nov 8, 2024

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

1 similar comment
Copy link
Contributor

github-actions bot commented Nov 8, 2024

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_responses.sh should be updated to clone the latest version of the responses: v5.2

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Test Results

   54 files   -   454     54 suites   - 454   2m 10s ⏱️ - 10m 41s
  517 tests  - 2 418    516 ✅  - 2 400  1 💤  - 18  0 ❌ ±0 
1 034 runs   - 4 936  1 032 ✅  - 4 900  2 💤  - 36  0 ❌ ±0 

Results for commit 82d9331. ± Comparison against base commit 4100ebf.

This pull request removes 2420 and adds 2 tests. Note that renamed tests count towards both.
com.google.firebase.CoroutinesPlayServicesTests ‑ Task#await() resolves to the same result as Task#getResult()
com.google.firebase.CoroutinesPlayServicesTests ‑ Task#await() throws an Exception for failing Tasks
com.google.firebase.DataCollectionPostNDefaultEnabledTest ‑ isDataCollectionDefaultEnabled_shouldDefaultToTrue
com.google.firebase.DataCollectionPostNDefaultEnabledTest ‑ isDataCollectionDefaultEnabled_whenPrefsFalse_shouldReturnFalse
com.google.firebase.DataCollectionPostNDefaultEnabledTest ‑ isDataCollectionDefaultEnabled_whenPrefsTrue_shouldReturnTrue
com.google.firebase.DataCollectionPostNDefaultEnabledTest ‑ setDataCollectionDefaultEnabledFalse_shouldUpdateSharedPrefs
com.google.firebase.DataCollectionPostNDefaultEnabledTest ‑ setDataCollectionDefaultEnabled_shouldNotAffectOtherFirebaseAppInstances
com.google.firebase.DataCollectionPreNDefaultEnabledTest ‑ isDataCollectionDefaultEnabled_shouldDefaultToTrue
com.google.firebase.DataCollectionPreNDefaultEnabledTest ‑ isDataCollectionDefaultEnabled_whenPrefsFalse_shouldReturnFalse
com.google.firebase.DataCollectionPreNDefaultEnabledTest ‑ isDataCollectionDefaultEnabled_whenPrefsTrue_shouldReturnTrue
…
com.google.firebase.dataconnect.core.FirebaseDataConnectImplUnitTest ‑ awaitAppCheckReady() should return once the provider is available
com.google.firebase.dataconnect.core.FirebaseDataConnectImplUnitTest ‑ awaitAuthReady() should return once the provider is available

@dconeybe dconeybe merged commit 5f6bc63 into main Nov 8, 2024
41 checks passed
@dconeybe dconeybe deleted the dconeybe/dataconnect/GrpcMetadataIntegrationTestRaceConditionFix branch November 8, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants