Fix flaky DownloadManager test

PiperOrigin-RevId: 350782940
This commit is contained in:
olly 2021-01-08 17:54:05 +00:00 committed by Ian Baker
parent c5df90b1ec
commit 9add3c764e

View File

@ -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.