Skip to content

Commit 26c8a5a

Browse files
authored
Fix flaky test (#6132)
Fix flaky `submitTaskFromAnotherWorkerDoesNotUseLocalThreads` test. This test would fail about 2% of the time on my machine due to dealing with threads. With this change, it fails less than 0.5% of the time. Tested by running the test in a loop 1,000 times.
1 parent 3a4ec18 commit 26c8a5a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public void submitTaskFromAnotherWorkerDoesNotUseLocalThreads() throws Exception
385385
Task<Integer> otherTask =
386386
crashlyticsWorker.submit(
387387
() -> {
388-
sleep(30);
388+
sleep(300);
389389
return localExecutor.getActiveCount();
390390
});
391391

@@ -395,6 +395,8 @@ public void submitTaskFromAnotherWorkerDoesNotUseLocalThreads() throws Exception
395395
// 1 active thread when doing a local task.
396396
assertThat(Tasks.await(localWorker.submit(localExecutor::getActiveCount))).isEqualTo(1);
397397

398+
sleep(1); // The test is a bit flaky without this.
399+
398400
// 0 active local threads when waiting for other task.
399401
// Waiting for a task from another worker does not block a local thread.
400402
assertThat(Tasks.await(localWorker.submitTask(() -> otherTask))).isEqualTo(0);

0 commit comments

Comments
 (0)