Skip to content

Commit 9716d09

Browse files
committed
Do not wait to store state when signing out
1 parent 1a0858d commit 9716d09

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,8 @@ public Task<Void> signInTester() {
244244

245245
@Override
246246
public void signOutTester() {
247-
cachedNewRelease
248-
.set(null)
249-
.addOnSuccessListener(lightweightExecutor, unused -> signInStorage.setSignInStatus(false));
247+
cachedNewRelease.set(null);
248+
signInStorage.setSignInStatus(false);
250249
}
251250

252251
@Override

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.HOST_ACTIVITY_INTERRUPTED;
2222
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.INSTALLATION_CANCELED;
2323
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.NETWORK_FAILURE;
24+
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.UNKNOWN;
2425
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.UPDATE_NOT_AVAILABLE;
2526
import static com.google.firebase.appdistribution.impl.ErrorMessages.AUTHENTICATION_ERROR;
2627
import static com.google.firebase.appdistribution.impl.ErrorMessages.JSON_PARSING_ERROR;
@@ -42,6 +43,7 @@
4243
import static org.junit.Assert.assertNull;
4344
import static org.junit.Assert.assertTrue;
4445
import static org.mockito.ArgumentMatchers.any;
46+
import static org.mockito.ArgumentMatchers.anyBoolean;
4547
import static org.mockito.Mockito.doReturn;
4648
import static org.mockito.Mockito.never;
4749
import static org.mockito.Mockito.spy;
@@ -68,6 +70,8 @@
6870
import com.google.android.gms.tasks.Tasks;
6971
import com.google.firebase.FirebaseApp;
7072
import com.google.firebase.FirebaseOptions;
73+
import com.google.firebase.annotations.concurrent.Blocking;
74+
import com.google.firebase.annotations.concurrent.Lightweight;
7175
import com.google.firebase.appdistribution.AppDistributionRelease;
7276
import com.google.firebase.appdistribution.BinaryType;
7377
import com.google.firebase.appdistribution.FirebaseAppDistributionException;
@@ -137,8 +141,8 @@ public class FirebaseAppDistributionServiceImplTest {
137141
.setDownloadUrl(TEST_URL)
138142
.build();
139143

140-
private final ExecutorService lightweightExecutor = TestOnlyExecutors.lite();
141-
private final ExecutorService blockingExecutor = TestOnlyExecutors.blocking();
144+
@Lightweight private final ExecutorService lightweightExecutor = TestOnlyExecutors.lite();
145+
@Blocking private final ExecutorService blockingExecutor = TestOnlyExecutors.blocking();
142146

143147
private FirebaseAppDistributionImpl firebaseAppDistribution;
144148
private ActivityController<TestActivity> activityController;
@@ -190,6 +194,7 @@ public void setup() throws FirebaseAppDistributionException {
190194

191195
when(mockTesterSignInManager.signInTester()).thenReturn(Tasks.forResult(null));
192196
when(mockSignInStorage.getSignInStatus()).thenReturn(Tasks.forResult(true));
197+
when(mockSignInStorage.setSignInStatus(anyBoolean())).thenReturn(Tasks.forResult(null));
193198

194199
when(mockInstallationTokenResult.getToken()).thenReturn(TEST_AUTH_TOKEN);
195200

@@ -506,12 +511,30 @@ private AlertDialog assertAlertDialogShown() {
506511
}
507512

508513
@Test
509-
public void signOutTester_setsSignInStatusFalse() throws InterruptedException {
514+
public void signOutTester_setsSignInStatusFalse(){
510515
firebaseAppDistribution.signOutTester();
511-
awaitTermination(lightweightExecutor);
516+
512517
verify(mockSignInStorage).setSignInStatus(false);
513518
}
514519

520+
@Test
521+
public void signOutTester_unsetsCachedNewRelease() throws InterruptedException, FirebaseAppDistributionException, ExecutionException {
522+
Task<AppDistributionReleaseInternal> setCachedNewReleaseTask = firebaseAppDistribution.getCachedNewRelease().set(TEST_RELEASE_NEWER_AAB_INTERNAL);
523+
524+
// Confirm that the cached new release is initially set
525+
awaitTask(setCachedNewReleaseTask);
526+
assertThat(setCachedNewReleaseTask.getResult()).isEqualTo(TEST_RELEASE_NEWER_AAB_INTERNAL);
527+
528+
// Sign out the tester
529+
firebaseAppDistribution.signOutTester();
530+
awaitAsyncOperations(lightweightExecutor);
531+
532+
// Confirm that the cached new release is now null
533+
Task<AppDistributionReleaseInternal> cachedNewReleaseTask = firebaseAppDistribution.getCachedNewRelease().get();
534+
awaitTask(cachedNewReleaseTask);
535+
assertThat(cachedNewReleaseTask.getResult()).isNull();
536+
}
537+
515538
@Test
516539
public void updateIfNewReleaseAvailable_receiveProgressUpdateFromUpdateApp()
517540
throws InterruptedException {
@@ -760,7 +783,7 @@ public void startFeedback_screenshotFails_startActivityWithNoScreenshot()
760783
throws InterruptedException {
761784
when(mockScreenshotTaker.takeScreenshot())
762785
.thenReturn(
763-
Tasks.forException(new FirebaseAppDistributionException("Error", Status.UNKNOWN)));
786+
Tasks.forException(new FirebaseAppDistributionException("Error", UNKNOWN)));
764787
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forResult("release-name"));
765788

766789
firebaseAppDistribution.startFeedback("Some terms and conditions");
@@ -781,7 +804,7 @@ public void startFeedback_signInTesterFails_logsAndSetsInProgressToFalse()
781804
throws InterruptedException {
782805
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forResult("release-name"));
783806
FirebaseAppDistributionException exception =
784-
new FirebaseAppDistributionException("Error", Status.UNKNOWN);
807+
new FirebaseAppDistributionException("Error", UNKNOWN);
785808
when(mockTesterSignInManager.signInTester()).thenReturn(Tasks.forException(exception));
786809

787810
firebaseAppDistribution.startFeedback("Some terms and conditions");
@@ -795,7 +818,7 @@ public void startFeedback_signInTesterFails_logsAndSetsInProgressToFalse()
795818
public void startFeedback_cantIdentifyRelease_logsAndSetsInProgressToFalse()
796819
throws InterruptedException {
797820
FirebaseAppDistributionException exception =
798-
new FirebaseAppDistributionException("Error", Status.UNKNOWN);
821+
new FirebaseAppDistributionException("Error", UNKNOWN);
799822
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forException(exception));
800823

801824
firebaseAppDistribution.startFeedback("Some terms and conditions");

0 commit comments

Comments
 (0)