Skip to content

Commit 9ef0e50

Browse files
committed
Use actual lightweight executor in test
1 parent e1bd329 commit 9ef0e50

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

firebase-appdistribution/firebase-appdistribution.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies {
4949
implementation project(':firebase-installations-interop')
5050
implementation project(':firebase-common')
5151
testImplementation project(path: ':firebase-appdistribution')
52+
testImplementation project(':integ-testing')
5253
runtimeOnly project(':firebase-installations')
5354

5455
testImplementation 'junit:junit:4.13.2'

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ void onActivityResumed(Activity activity) {
320320
cachedNewRelease
321321
.get()
322322
.addOnSuccessListener(
323+
lightweightExecutor,
323324
release ->
324325
showUpdateConfirmationDialog(
325326
activity, ReleaseUtils.convertToAppDistributionRelease(release)));

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionServiceImplTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.google.firebase.appdistribution.UpdateStatus;
6666
import com.google.firebase.appdistribution.UpdateTask;
6767
import com.google.firebase.concurrent.FirebaseExecutors;
68+
import com.google.firebase.concurrent.TestOnlyExecutors;
6869
import com.google.firebase.installations.InstallationTokenResult;
6970
import java.util.ArrayList;
7071
import java.util.List;
@@ -119,7 +120,7 @@ public class FirebaseAppDistributionServiceImplTest {
119120
.setDownloadUrl(TEST_URL)
120121
.build();
121122

122-
private final ExecutorService testExecutor = Executors.newSingleThreadExecutor();
123+
private final ExecutorService lightweightExecutor = TestOnlyExecutors.lite();
123124

124125
private FirebaseAppDistributionImpl firebaseAppDistribution;
125126
private TestActivity activity;
@@ -161,7 +162,7 @@ public void setup() throws FirebaseAppDistributionException {
161162
mockAabUpdater,
162163
mockSignInStorage,
163164
mockLifecycleNotifier,
164-
testExecutor));
165+
lightweightExecutor));
165166

166167
when(mockTesterSignInManager.signInTester()).thenReturn(Tasks.forResult(null));
167168
when(mockSignInStorage.getSignInStatus()).thenReturn(true);
@@ -236,7 +237,7 @@ public void checkForNewRelease_authenticationFailure_signOutTester() throws Inte
236237
Task<AppDistributionRelease> task = firebaseAppDistribution.checkForNewRelease();
237238

238239
awaitTaskFailure(task, AUTHENTICATION_FAILURE, "Test");
239-
awaitTermination(testExecutor);
240+
awaitTermination(lightweightExecutor);
240241
verify(mockSignInStorage, times(1)).setSignInStatus(false);
241242
}
242243

@@ -256,7 +257,7 @@ public void updateIfNewReleaseAvailable_whenNewAabReleaseAvailable_showsUpdateDi
256257
.thenReturn(Tasks.forResult((TEST_RELEASE_NEWER_AAB_INTERNAL)));
257258

258259
firebaseAppDistribution.updateIfNewReleaseAvailable();
259-
awaitAsyncOperations(testExecutor);
260+
awaitAsyncOperations(lightweightExecutor);
260261

261262
AlertDialog dialog = assertAlertDialogShown();
262263
assertEquals(
@@ -290,7 +291,7 @@ public void updateIfNewReleaseAvailable_whenReleaseNotesEmpty_doesNotShowRelease
290291
(TEST_RELEASE_NEWER_AAB_INTERNAL.toBuilder().setReleaseNotes("").build())));
291292

292293
firebaseAppDistribution.updateIfNewReleaseAvailable();
293-
awaitAsyncOperations(testExecutor);
294+
awaitAsyncOperations(lightweightExecutor);
294295

295296
AlertDialog dialog = assertAlertDialogShown();
296297
assertEquals(
@@ -309,7 +310,7 @@ public void updateIfNewReleaseAvailable_whenNoReleaseAvailable_updateDialogNotSh
309310

310311
List<UpdateProgress> progressEvents = new ArrayList<>();
311312
task.addOnProgressListener(FirebaseExecutors.directExecutor(), progressEvents::add);
312-
awaitTermination(testExecutor);
313+
awaitTermination(lightweightExecutor);
313314

314315
assertEquals(1, progressEvents.size());
315316
assertEquals(UpdateStatus.NEW_RELEASE_NOT_AVAILABLE, progressEvents.get(0).getUpdateStatus());
@@ -325,7 +326,7 @@ public void updateIfNewReleaseAvailable_whenActivityBackgrounded_updateDialogNot
325326

326327
List<UpdateProgress> progressEvents = new ArrayList<>();
327328
task.addOnProgressListener(FirebaseExecutors.directExecutor(), progressEvents::add);
328-
awaitTermination(testExecutor);
329+
awaitTermination(lightweightExecutor);
329330

330331
assertEquals(1, progressEvents.size());
331332
assertEquals(UpdateStatus.NEW_RELEASE_NOT_AVAILABLE, progressEvents.get(0).getUpdateStatus());
@@ -375,7 +376,7 @@ public void updateIfNewReleaseAvailable_whenDialogDismissed_taskFails()
375376
.thenReturn(Tasks.forResult(TEST_RELEASE_NEWER_AAB_INTERNAL));
376377

377378
UpdateTask updateTask = firebaseAppDistribution.updateIfNewReleaseAvailable();
378-
awaitAsyncOperations(testExecutor);
379+
awaitAsyncOperations(lightweightExecutor);
379380

380381
AlertDialog updateDialog = assertAlertDialogShown();
381382
updateDialog.getButton(AlertDialog.BUTTON_NEGATIVE).performClick(); // dismiss dialog
@@ -393,7 +394,7 @@ public void updateIfNewReleaseAvailable_whenDialogCanceled_taskFails()
393394
UpdateTask updateTask = firebaseAppDistribution.updateIfNewReleaseAvailable();
394395

395396
// Task callbacks happen on the executor
396-
awaitTermination(testExecutor);
397+
awaitTermination(lightweightExecutor);
397398

398399
// Show update confirmation dialog happens on the UI thread
399400
shadowOf(getMainLooper()).idle();
@@ -469,7 +470,7 @@ private AlertDialog assertAlertDialogShown() {
469470
@Test
470471
public void signOutTester_setsSignInStatusFalse() throws InterruptedException {
471472
firebaseAppDistribution.signOutTester();
472-
awaitTermination(testExecutor);
473+
awaitTermination(lightweightExecutor);
473474
verify(mockSignInStorage).setSignInStatus(false);
474475
}
475476

@@ -491,12 +492,12 @@ public void updateIfNewReleaseAvailable_receiveProgressUpdateFromUpdateApp()
491492

492493
List<UpdateProgress> progressEvents = new ArrayList<>();
493494
updateTask.addOnProgressListener(FirebaseExecutors.directExecutor(), progressEvents::add);
494-
awaitAsyncOperations(testExecutor);
495+
awaitAsyncOperations(lightweightExecutor);
495496

496497
// Clicking the update button.
497498
AlertDialog updateDialog = (AlertDialog) ShadowAlertDialog.getLatestDialog();
498499
updateDialog.getButton(Dialog.BUTTON_POSITIVE).performClick();
499-
awaitAsyncOperations(testExecutor);
500+
awaitAsyncOperations(lightweightExecutor);
500501

501502
// Update flow
502503
assertEquals(1, progressEvents.size());
@@ -541,7 +542,7 @@ public void updateIfNewReleaseAvailable_whenScreenRotates_updateDialogReappears(
541542
when(activity.isChangingConfigurations()).thenReturn(true);
542543

543544
UpdateTask updateTask = firebaseAppDistribution.updateIfNewReleaseAvailable();
544-
awaitAsyncOperations(testExecutor);
545+
awaitAsyncOperations(lightweightExecutor);
545546

546547
// Mimic activity recreation due to a configuration change
547548
firebaseAppDistribution.onActivityDestroyed(activity);
@@ -576,7 +577,7 @@ public void updateIfNewReleaseAvailable_whenScreenRotates_updateDialogReappears(
576577
when(mockNewReleaseFetcher.checkForNewRelease()).thenReturn(Tasks.forResult(newRelease));
577578

578579
UpdateTask updateTask = firebaseAppDistribution.updateIfNewReleaseAvailable();
579-
awaitAsyncOperations(testExecutor);
580+
awaitAsyncOperations(lightweightExecutor);
580581

581582
// Mimic different activity getting resumed
582583
firebaseAppDistribution.onActivityPaused(activity);

0 commit comments

Comments
 (0)