Skip to content

Commit fd473d0

Browse files
committed
More tests about tasks from other workers
1 parent 7ca8f55 commit fd473d0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,43 @@ public void submitTaskFromAnotherWorker() throws Exception {
281281
assertThat(result).isEqualTo("Dog's fine. Just sleeping.");
282282
}
283283

284+
@Test
285+
public void submitTaskFromAnotherWorkerThatThrows() throws Exception {
286+
Task<?> otherTask =
287+
new CrashlyticsWorker(TestOnlyExecutors.blocking())
288+
.submitTask(() -> Tasks.forException(new IndexOutOfBoundsException()));
289+
290+
// Await on the throwing task to force the exception to propagate.
291+
assertThrows(ExecutionException.class, () -> Tasks.await(otherTask));
292+
293+
// Submit another task to local worker to verify the chain did not break.
294+
Task<Long> localTask = crashlyticsWorker.submitTask(() -> Tasks.forResult(0x5fe6eb50c7b537a9L));
295+
296+
Long localResult = Tasks.await(localTask);
297+
298+
assertThat(otherTask.isSuccessful()).isFalse();
299+
assertThat(localTask.isSuccessful()).isTrue();
300+
assertThat(localResult).isEqualTo(0x5fe6eb50c7b537a9L);
301+
}
302+
303+
@Test
304+
public void submitTaskFromAnotherWorkerThatCancels() throws Exception {
305+
Task<?> otherCancelled =
306+
new CrashlyticsWorker(TestOnlyExecutors.blocking()).submitTask(Tasks::forCanceled);
307+
308+
// Await on the cancelled task to force the exception to propagate.
309+
assertThrows(CancellationException.class, () -> Tasks.await(otherCancelled));
310+
311+
// Submit another task to local worker to verify the chain did not break.
312+
Task<Long> localTask = crashlyticsWorker.submitTask(() -> Tasks.forResult(0x5fe6eb50c7b537a9L));
313+
314+
Long localResult = Tasks.await(localTask);
315+
316+
assertThat(otherCancelled.isCanceled()).isTrue();
317+
assertThat(localTask.isCanceled()).isFalse();
318+
assertThat(localResult).isEqualTo(0x5fe6eb50c7b537a9L);
319+
}
320+
284321
@Test
285322
public void submitTaskFromAnotherWorkerDoesNotUseLocalThreads() throws Exception {
286323
// Setup a "local" worker.

0 commit comments

Comments
 (0)