From c1529c46d819c1190cada7aeff73c26efd0775dc Mon Sep 17 00:00:00 2001 From: olly Date: Fri, 8 Jan 2021 17:54:05 +0000 Subject: [PATCH] Fix flaky DownloadManager test #minor-release PiperOrigin-RevId: 350782940 --- .../exoplayer2/offline/DownloadManagerTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java index fc050a068a..88108d55a1 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java @@ -25,6 +25,7 @@ import androidx.annotation.Nullable; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.offline.DownloadManager.Listener; import com.google.android.exoplayer2.robolectric.TestDownloadManagerListener; import com.google.android.exoplayer2.scheduler.Requirements; import com.google.android.exoplayer2.testutil.DownloadBuilder; @@ -622,11 +623,23 @@ public class DownloadManagerTest { downloadRemover.assertRemoveStarted(); // Re-add the download with a stop reason. + ConditionVariable downloadManagerIdleCondition = new ConditionVariable(); runOnMainThread( - () -> downloadManager.addDownload(createDownloadRequest(ID1), /* stopReason= */ 1234)); + () -> { + downloadManager.addListener( + new Listener() { + @Override + public void onIdle(DownloadManager downloadManager) { + downloadManagerIdleCondition.open(); + } + }); + downloadManager.addDownload(createDownloadRequest(ID1), /* stopReason= */ 1234); + }); downloadRemover.finish(); + assertThat(downloadManagerIdleCondition.block(TIMEOUT_MS)).isTrue(); + assertDownloadIndexSize(1); // We expect one downloader for the initial download, and one for the removal. A downloader // should not be created when the download is re-added, since a stop reason is specified.