diff options
author | Herbert Reiter <46045854+damoasda@users.noreply.github.com> | 2020-12-30 15:15:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-30 15:15:23 +0100 |
commit | 994ee0e0a2c5bc62c06ae1ecf65ffb0ad662ff6a (patch) | |
tree | 57b6b8578205735fec8a8cf394303582d7ee0348 /core/src | |
parent | dcd40d4caca55b5fb85e4a9e8f958f3cc490448a (diff) | |
download | AntennaPod-994ee0e0a2c5bc62c06ae1ecf65ffb0ad662ff6a.zip |
Fix #4775: Illegal connection pointer in Robolectric tests (awaitTermination) (#4794)
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java | 13 | ||||
-rw-r--r-- | core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java index cb205cbf7..84cc4b6a8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java @@ -21,6 +21,7 @@ import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.event.DownloadLogEvent; @@ -73,6 +74,18 @@ public class DBWriter { } /** + * Wait until all threads are finished to avoid the "Illegal connection pointer" error of + * Robolectric. Call this method only for unit tests. + */ + public static void tearDownTests() { + try { + dbExec.awaitTermination(1, TimeUnit.SECONDS); + } catch (InterruptedException e) { + // ignore error + } + } + + /** * Deletes a downloaded FeedMedia file from the storage device. * * @param context A context that is used for opening a database connection. diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java index a634833c9..fbe4c6ace 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/LocalFeedUpdaterTest.java @@ -30,6 +30,7 @@ import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.PodDBAdapter; import static org.junit.Assert.assertEquals; @@ -81,6 +82,7 @@ public class LocalFeedUpdaterTest { @After public void tearDown() { + DBWriter.tearDownTests(); PodDBAdapter.tearDownTests(); } |