Fix #4775: Illegal connection pointer in Robolectric tests (awaitTermination) (#4794)

This commit is contained in:
Herbert Reiter 2020-12-30 15:15:23 +01:00 committed by GitHub
parent dcd40d4cac
commit 994ee0e0a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -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;
@ -72,6 +73,18 @@ public class DBWriter {
private 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.
*

View File

@ -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();
}