summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2019-12-02 13:02:09 +0100
committerByteHamster <info@bytehamster.com>2019-12-12 09:47:16 +0100
commit44aa0a3239ee5fba3dc17f6f7e91fa5f24b737fc (patch)
tree343c58046c519c3a50f309a13e145fca91a9d708 /app/src
parente2aa83f047e8ca762c19290a620fe47d154b74eb (diff)
downloadAntennaPod-44aa0a3239ee5fba3dc17f6f7e91fa5f24b737fc.zip
Try to kill playback service but do not fail if it does not stop
Android has no reliable way to stop a service instantly. Calling stopSelf marks allows the system to destroy the service but the actual call to onDestroy takes until the next GC of the system, which we can not influence. Try to wait for the service at least a bit.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java20
-rw-r--r--app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java7
-rw-r--r--app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java4
-rw-r--r--app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java4
4 files changed, 25 insertions, 10 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
index d4d589859..31543a94a 100644
--- a/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
+++ b/app/src/androidTest/java/de/test/antennapod/EspressoTestUtils.java
@@ -1,6 +1,7 @@
package de.test.antennapod;
import android.content.Context;
+import android.content.Intent;
import androidx.annotation.IdRes;
import androidx.annotation.StringRes;
import androidx.test.InstrumentationRegistry;
@@ -15,11 +16,15 @@ import androidx.test.espresso.util.TreeIterables;
import android.view.View;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
+import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.dialog.RatingDialog;
+import org.awaitility.Awaitility;
+import org.awaitility.core.ConditionTimeoutException;
import org.hamcrest.Matcher;
import java.io.File;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static androidx.test.espresso.Espresso.onView;
@@ -156,4 +161,19 @@ public class EspressoTestUtils {
public static ViewInteraction onDrawerItem(Matcher<View> viewMatcher) {
return onView(allOf(viewMatcher, withId(R.id.txtvTitle)));
}
+
+ public static void tryKillPlaybackService() {
+ Context context = InstrumentationRegistry.getTargetContext();
+ context.stopService(new Intent(context, PlaybackService.class));
+ try {
+ // Android has no reliable way to stop a service instantly.
+ // Calling stopSelf marks allows the system to destroy the service but the actual call
+ // to onDestroy takes until the next GC of the system, which we can not influence.
+ // Try to wait for the service at least a bit.
+ Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> !PlaybackService.isRunning);
+ } catch (ConditionTimeoutException e) {
+ e.printStackTrace();
+ }
+ androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ }
}
diff --git a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java
index 036eda3aa..1a2a7e29e 100644
--- a/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/playback/PlaybackTest.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
+import android.view.KeyEvent;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
@@ -11,6 +12,7 @@ import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
+import de.danoeh.antennapod.core.receiver.MediaButtonReceiver;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.storage.DBReader;
@@ -87,10 +89,7 @@ public class PlaybackTest {
@After
public void tearDown() throws Exception {
activityTestRule.finishActivity();
- Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
- context.stopService(new Intent(context, PlaybackService.class));
- Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> !PlaybackService.isRunning);
- InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ EspressoTestUtils.tryKillPlaybackService();
uiTestUtils.tearDown();
}
diff --git a/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java b/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java
index a00dc6517..b89f1b9bc 100644
--- a/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/storage/AutoDownloadTest.java
@@ -60,9 +60,7 @@ public class AutoDownloadTest {
@After
public void tearDown() throws Exception {
ClientConfig.dbTasksCallbacks = dbTasksCallbacksOrig;
- context.stopService(new Intent(context, PlaybackService.class));
- Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> !PlaybackService.isRunning);
- InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+ EspressoTestUtils.tryKillPlaybackService();
stubFeedsServer.tearDown();
}
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java b/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java
index 84a7a23bb..ff797b9bc 100644
--- a/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java
+++ b/app/src/androidTest/java/de/test/antennapod/ui/SpeedChangeTest.java
@@ -68,9 +68,7 @@ public class SpeedChangeTest {
UserPreferences.setPlaybackSpeedArray(new String[] {"1.00", "2.00", "3.00"});
availableSpeeds = UserPreferences.getPlaybackSpeedArray();
- context.sendBroadcast(new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE));
- Awaitility.await().until(() -> !PlaybackService.isRunning);
-
+ EspressoTestUtils.tryKillPlaybackService();
activityRule.launchActivity(new Intent());
}