diff options
author | ByteHamster <info@bytehamster.com> | 2020-03-20 14:34:03 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-03-20 15:55:26 +0100 |
commit | c336ac24d4e7df9ac35e97fb3657155b0e0189d4 (patch) | |
tree | c7c75fccc3178d546e13bab208fa25ce35603760 /app/src/androidTest/java/de/test/antennapod/service | |
parent | 0d029438665d232dfe1a245cbe03bb51b76be2c6 (diff) | |
download | AntennaPod-c336ac24d4e7df9ac35e97fb3657155b0e0189d4.zip |
Give cancelling downloads more time
The first download installs the ssl security provider and might block
around 1.2 seconds longer than in previous versions.
Diffstat (limited to 'app/src/androidTest/java/de/test/antennapod/service')
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java b/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java index 1ca4de1ad..229d4b307 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/download/DownloadServiceTest.java @@ -16,6 +16,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -36,6 +37,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Consumer; +import static de.test.antennapod.util.event.DownloadEventListener.withDownloadEventListener; import static de.test.antennapod.util.event.FeedItemEventListener.withFeedItemEventListener; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -119,8 +121,9 @@ public class DownloadServiceTest { DBReader.getFeedMedia(testMedia11.getId()).isDownloaded()); DownloadRequester.getInstance().downloadMedia(false, InstrumentationRegistry.getTargetContext(), - testMedia11.getItem());Awaitility.await() - .atMost(1000, TimeUnit.MILLISECONDS) + testMedia11.getItem()); + Awaitility.await() + .atMost(5000, TimeUnit.MILLISECONDS) .until(() -> feedItemEventListener.getEvents().size() >= numEventsExpected); assertTrue("After media download has completed, FeedMedia object in db should indicate so.", DBReader.getFeedMedia(testMedia11.getId()).isDownloaded()); @@ -146,8 +149,8 @@ public class DownloadServiceTest { private void doTestCancelDownload_UndoEnqueue(boolean itemAlreadyInQueue) throws Exception { Context context = InstrumentationRegistry.getTargetContext(); - // let download takes longer to ensure the test can cancel the download in time - DownloadService.setDownloaderFactory(new StubDownloaderFactory(10000, downloadStatus -> { + // let download take longer to ensure the test can cancel the download in time + DownloadService.setDownloaderFactory(new StubDownloaderFactory(30000, downloadStatus -> { downloadStatus.setSuccessful(); })); UserPreferences.setEnqueueDownloadedEpisodes(true); @@ -164,11 +167,16 @@ public class DownloadServiceTest { withFeedItemEventListener(feedItemEventListener -> { DownloadRequester.getInstance().downloadMedia(false, context, testMedia11.getItem()); + withDownloadEventListener(downloadEventListener -> + Awaitility.await("download is actually running") + .atMost(5000, TimeUnit.MILLISECONDS) + .until(() -> downloadEventListener.getLatestEvent() != null + && downloadEventListener.getLatestEvent().update.mediaIds.length > 0 + && downloadEventListener.getLatestEvent().update.mediaIds[0] == testMedia11.getId())); + if (itemAlreadyInQueue) { - Awaitility.await("download service receives the request - " - + "no event is expected before cancel is issued") - .atLeast(100, TimeUnit.MILLISECONDS) - .until(() -> true); + assertEquals("download service receives the request - no event is expected before cancel is issued", + 0, feedItemEventListener.getEvents().size()); } else { Awaitility.await("item enqueue event") .atMost(2000, TimeUnit.MILLISECONDS) @@ -177,7 +185,7 @@ public class DownloadServiceTest { DownloadRequester.getInstance().cancelDownload(context, testMedia11); final int totalNumEventsExpected = itemAlreadyInQueue ? 1 : 3; Awaitility.await("item dequeue event + download termination event") - .atMost(1000, TimeUnit.MILLISECONDS) + .atMost(2000, TimeUnit.MILLISECONDS) .until(() -> feedItemEventListener.getEvents().size() >= totalNumEventsExpected); assertFalse("The download should have been canceled", DBReader.getFeedMedia(testMedia11.getId()).isDownloaded()); |