Skip to content

Commit 9afb4ba

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

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
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: 33 additions & 8 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,33 @@ 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()
522+
throws InterruptedException, FirebaseAppDistributionException, ExecutionException {
523+
Task<AppDistributionReleaseInternal> setCachedNewReleaseTask =
524+
firebaseAppDistribution.getCachedNewRelease().set(TEST_RELEASE_NEWER_AAB_INTERNAL);
525+
526+
// Confirm that the cached new release is initially set
527+
awaitTask(setCachedNewReleaseTask);
528+
assertThat(setCachedNewReleaseTask.getResult()).isEqualTo(TEST_RELEASE_NEWER_AAB_INTERNAL);
529+
530+
// Sign out the tester
531+
firebaseAppDistribution.signOutTester();
532+
awaitAsyncOperations(lightweightExecutor);
533+
534+
// Confirm that the cached new release is now null
535+
Task<AppDistributionReleaseInternal> cachedNewReleaseTask =
536+
firebaseAppDistribution.getCachedNewRelease().get();
537+
awaitTask(cachedNewReleaseTask);
538+
assertThat(cachedNewReleaseTask.getResult()).isNull();
539+
}
540+
515541
@Test
516542
public void updateIfNewReleaseAvailable_receiveProgressUpdateFromUpdateApp()
517543
throws InterruptedException {
@@ -759,8 +785,7 @@ public boolean isFinishing() {
759785
public void startFeedback_screenshotFails_startActivityWithNoScreenshot()
760786
throws InterruptedException {
761787
when(mockScreenshotTaker.takeScreenshot())
762-
.thenReturn(
763-
Tasks.forException(new FirebaseAppDistributionException("Error", Status.UNKNOWN)));
788+
.thenReturn(Tasks.forException(new FirebaseAppDistributionException("Error", UNKNOWN)));
764789
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forResult("release-name"));
765790

766791
firebaseAppDistribution.startFeedback("Some terms and conditions");
@@ -781,7 +806,7 @@ public void startFeedback_signInTesterFails_logsAndSetsInProgressToFalse()
781806
throws InterruptedException {
782807
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forResult("release-name"));
783808
FirebaseAppDistributionException exception =
784-
new FirebaseAppDistributionException("Error", Status.UNKNOWN);
809+
new FirebaseAppDistributionException("Error", UNKNOWN);
785810
when(mockTesterSignInManager.signInTester()).thenReturn(Tasks.forException(exception));
786811

787812
firebaseAppDistribution.startFeedback("Some terms and conditions");
@@ -795,7 +820,7 @@ public void startFeedback_signInTesterFails_logsAndSetsInProgressToFalse()
795820
public void startFeedback_cantIdentifyRelease_logsAndSetsInProgressToFalse()
796821
throws InterruptedException {
797822
FirebaseAppDistributionException exception =
798-
new FirebaseAppDistributionException("Error", Status.UNKNOWN);
823+
new FirebaseAppDistributionException("Error", UNKNOWN);
799824
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forException(exception));
800825

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

0 commit comments

Comments
 (0)