Skip to content

Commit 973f40e

Browse files
authored
Do not wait to store state when signing out (#4490)
* Do not wait to store state when signing out * Remove unnecessary assertions during test setup
1 parent 1a0858d commit 973f40e

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-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: 27 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,27 @@ 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+
awaitTask(setCachedNewReleaseTask);
526+
527+
firebaseAppDistribution.signOutTester();
528+
529+
Task<AppDistributionReleaseInternal> cachedNewReleaseTask =
530+
firebaseAppDistribution.getCachedNewRelease().get();
531+
awaitTask(cachedNewReleaseTask);
532+
assertThat(cachedNewReleaseTask.getResult()).isNull();
533+
}
534+
515535
@Test
516536
public void updateIfNewReleaseAvailable_receiveProgressUpdateFromUpdateApp()
517537
throws InterruptedException {
@@ -759,8 +779,7 @@ public boolean isFinishing() {
759779
public void startFeedback_screenshotFails_startActivityWithNoScreenshot()
760780
throws InterruptedException {
761781
when(mockScreenshotTaker.takeScreenshot())
762-
.thenReturn(
763-
Tasks.forException(new FirebaseAppDistributionException("Error", Status.UNKNOWN)));
782+
.thenReturn(Tasks.forException(new FirebaseAppDistributionException("Error", UNKNOWN)));
764783
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forResult("release-name"));
765784

766785
firebaseAppDistribution.startFeedback("Some terms and conditions");
@@ -781,7 +800,7 @@ public void startFeedback_signInTesterFails_logsAndSetsInProgressToFalse()
781800
throws InterruptedException {
782801
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forResult("release-name"));
783802
FirebaseAppDistributionException exception =
784-
new FirebaseAppDistributionException("Error", Status.UNKNOWN);
803+
new FirebaseAppDistributionException("Error", UNKNOWN);
785804
when(mockTesterSignInManager.signInTester()).thenReturn(Tasks.forException(exception));
786805

787806
firebaseAppDistribution.startFeedback("Some terms and conditions");
@@ -795,7 +814,7 @@ public void startFeedback_signInTesterFails_logsAndSetsInProgressToFalse()
795814
public void startFeedback_cantIdentifyRelease_logsAndSetsInProgressToFalse()
796815
throws InterruptedException {
797816
FirebaseAppDistributionException exception =
798-
new FirebaseAppDistributionException("Error", Status.UNKNOWN);
817+
new FirebaseAppDistributionException("Error", UNKNOWN);
799818
when(mockReleaseIdentifier.identifyRelease()).thenReturn(Tasks.forException(exception));
800819

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

0 commit comments

Comments
 (0)