Faster unit tests (#8043)

This commit is contained in:
Hans-Peter Lehmann 2025-10-14 07:43:10 +02:00 committed by GitHub
parent 20601cc859
commit 77c813f62c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

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

View File

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