mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-10-29 03:36:21 +00:00
Faster unit tests (#8043)
This commit is contained in:
parent
20601cc859
commit
77c813f62c
@ -469,7 +469,7 @@ public class DbReaderTest {
|
||||
private int paramOffset;
|
||||
private int paramLimit;
|
||||
|
||||
@ParameterizedRobolectricTestRunner.Parameters
|
||||
@ParameterizedRobolectricTestRunner.Parameters(name = "offset={0} limit={1}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Integer> limits = Arrays.asList(1, 20, 100);
|
||||
List<Integer> offsets = Arrays.asList(0, 10, 20);
|
||||
|
||||
@ -33,7 +33,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import de.danoeh.antennapod.event.FavoritesEvent;
|
||||
import de.danoeh.antennapod.event.FeedItemEvent;
|
||||
@ -82,10 +82,18 @@ public class DBWriter {
|
||||
* Robolectric. Call this method only for unit tests.
|
||||
*/
|
||||
public static void tearDownTests() {
|
||||
// dbExec is single-threaded FIFO, so if a newly submitted task runs, all previous tasks must have finished
|
||||
final Semaphore available = new Semaphore(1, true);
|
||||
try {
|
||||
dbExec.awaitTermination(1, TimeUnit.SECONDS);
|
||||
available.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
// ignore error
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
dbExec.submit(() -> available.release());
|
||||
try {
|
||||
available.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user