Commit 9add3c76 by olly Committed by Ian Baker

Fix flaky DownloadManager test

PiperOrigin-RevId: 350782940
parent c5df90b1
......@@ -24,6 +24,8 @@ 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;
import com.google.android.exoplayer2.testutil.DummyMainThread;
......@@ -621,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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment