Skip to content

Commit 03fb48d

Browse files
committed
Address feedback
1 parent fded039 commit 03fb48d

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/concurrency/CrashlyticsWorkerTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,26 @@ public void submitTaskWithContinuationThatCancels() throws Exception {
487487
assertThat(Tasks.await(crashlyticsWorker.submit(() -> "jk"))).isEqualTo("jk");
488488
}
489489

490+
@Test
491+
public void submitTaskOnSuccess() throws Exception {
492+
TaskCompletionSource<Integer> waitingSource = new TaskCompletionSource<>();
493+
Task<Integer> waitingTask = waitingSource.getTask();
494+
495+
Task<String> task =
496+
crashlyticsWorker.submitTaskOnSuccess(
497+
() -> waitingTask,
498+
integerResult -> {
499+
// This gets called with the result when the waiting task resolves successfully.
500+
return Tasks.forResult(integerResult + " Success!");
501+
});
502+
503+
waitingSource.trySetResult(1337);
504+
505+
String result = Tasks.await(task);
506+
507+
assertThat(result).isEqualTo("1337 Success!");
508+
}
509+
490510
@Test
491511
public void submitTaskThatReturnsWithSuccessContinuation() throws Exception {
492512
Task<String> task =
@@ -499,7 +519,7 @@ public void submitTaskThatReturnsWithSuccessContinuation() throws Exception {
499519
}
500520

501521
@Test
502-
public void submitTaskThatThrowsWithSuccessContinuation() throws Exception {
522+
public void submitTaskThatThrowsWithSuccessContinuation() {
503523
Task<String> task =
504524
crashlyticsWorker.submitTaskOnSuccess(
505525
() -> Tasks.forException(new IndexOutOfBoundsException()),

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/metadata/MetaDataStoreTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void testWriteUserData_allFields() throws Exception {
9393
storeUnderTest.writeUserData(SESSION_ID_1, metadataWithUserId(SESSION_ID_1).getUserId());
9494
});
9595
crashlyticsWorkers.diskWrite.await();
96+
Thread.sleep(5);
9697
UserMetadata userData =
9798
UserMetadata.loadFromExistingSession(SESSION_ID_1, fileStore, crashlyticsWorkers);
9899
assertEquals(USER_ID, userData.getUserId());

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.firebase.crashlytics.internal.Logger;
3434
import com.google.firebase.crashlytics.internal.NativeSessionFileProvider;
3535
import com.google.firebase.crashlytics.internal.analytics.AnalyticsEventLogger;
36+
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsTasks;
3637
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorkers;
3738
import com.google.firebase.crashlytics.internal.metadata.LogFileManager;
3839
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
@@ -296,7 +297,7 @@ public Task<Boolean> then(@Nullable Void aVoid) throws Exception {
296297

297298
Logger.getLogger().d("Waiting for send/deleteUnsentReports to be called.");
298299
// Wait for either the processReports callback to be called, or data collection to be enabled.
299-
return Utils.race(collectionEnabled, reportActionProvided.getTask());
300+
return CrashlyticsTasks.race(collectionEnabled, reportActionProvided.getTask());
300301
}
301302

302303
/** This function must be called before opening the first session * */

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/Utils.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414

1515
package com.google.firebase.crashlytics.internal.common;
1616

17-
import android.annotation.SuppressLint;
1817
import android.os.Looper;
19-
import com.google.android.gms.tasks.Continuation;
2018
import com.google.android.gms.tasks.Task;
21-
import com.google.android.gms.tasks.TaskCompletionSource;
2219
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2320
import java.util.concurrent.CancellationException;
2421
import java.util.concurrent.CountDownLatch;
@@ -35,27 +32,6 @@ public final class Utils {
3532
/** Timeout in milliseconds for blocking on the main thread. Be careful about ANRs. */
3633
private static final int MAIN_TIMEOUT_MILLIS = 2_750;
3734

38-
/**
39-
* @return A tasks that is resolved when either of the given tasks is resolved.
40-
*/
41-
// TODO(b/261014167): Use an explicit executor in continuations.
42-
@SuppressLint("TaskMainThread")
43-
public static <T> Task<T> race(Task<T> t1, Task<T> t2) {
44-
final TaskCompletionSource<T> result = new TaskCompletionSource<>();
45-
Continuation<T, Void> continuation =
46-
task -> {
47-
if (task.isSuccessful()) {
48-
result.trySetResult(task.getResult());
49-
} else if (task.getException() != null) {
50-
result.trySetException(task.getException());
51-
}
52-
return null;
53-
};
54-
t1.continueWith(continuation);
55-
t2.continueWith(continuation);
56-
return result.getTask();
57-
}
58-
5935
/**
6036
* Blocks until the given Task completes, and then returns the value the Task was resolved with,
6137
* if successful. If the Task fails, an exception will be thrown, wrapping the Exception of the

0 commit comments

Comments
 (0)