Make emulator tests more stable (#8124)

This commit is contained in:
Hans-Peter Lehmann
2025-11-30 21:26:04 +01:00
committed by GitHub
parent 84b596bffd
commit cafb52766b
4 changed files with 23 additions and 23 deletions

View File

@ -154,7 +154,7 @@ jobs:
if: failure()
with:
name: test-report
path: app/build/reports/androidTests/connected/flavors/PLAY/
path: app/build/reports/androidTests/
ci-summary:
name: "CI Summary"

View File

@ -1,6 +1,7 @@
#!/bin/bash
set -o pipefail
adb logcat -c
runTests() {
./gradlew connectedPlayDebugAndroidTest connectedDebugAndroidTest \
@ -8,4 +9,11 @@ runTests() {
}
# Retry tests to make them less flaky
runTests || runTests || runTests
if runTests || runTests || runTests; then
echo "Tests succeeded"
else
echo "Tests FAILED. Dumping logcat:"
adb logcat -d > app/build/reports/androidTests/logcat.txt
exit 1
fi

View File

@ -99,9 +99,8 @@ public class EspressoTestUtils {
*
* @param viewMatcher The view to wait for.
* @param timeoutMillis Maximum waiting period in milliseconds.
* @throws Exception Throws an Exception in case of a timeout.
*/
public static void waitForViewGlobally(@NonNull Matcher<View> viewMatcher, long timeoutMillis) throws Exception {
public static void waitForViewGlobally(@NonNull Matcher<View> viewMatcher, long timeoutMillis) {
long startTime = System.currentTimeMillis();
long endTime = startTime + timeoutMillis;
@ -110,14 +109,21 @@ public class EspressoTestUtils {
onView(viewMatcher).check(matches(isDisplayed()));
// no Exception thrown -> check successful
return;
} catch (NoMatchingViewException | AssertionFailedError ignore) {
} catch (NoMatchingViewException | AssertionFailedError exception) {
// check was not successful "not found" -> continue waiting
if (System.currentTimeMillis() >= endTime) {
throw exception;
}
}
//noinspection BusyWait
Thread.sleep(50);
} while (System.currentTimeMillis() < endTime);
try {
//noinspection BusyWait
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
} while (true);
throw new Exception("Timeout after " + timeoutMillis + " ms");
throw new RuntimeException("Timeout after " + timeoutMillis + " ms");
}
/**

View File

@ -1,7 +1,6 @@
package de.danoeh.antennapod;
import android.app.Application;
import android.os.StrictMode;
import android.util.Log;
import com.google.android.material.color.DynamicColors;
@ -19,19 +18,6 @@ public class PodcastApp extends Application {
Thread.setDefaultUncaughtExceptionHandler(new CrashReportExceptionHandler());
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
if (BuildConfig.DEBUG) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder()
.penaltyDeath()
.penaltyLog()
.detectLeakedSqlLiteObjects()
.detectActivityLeaks()
.detectLeakedRegistrationObjects();
if (android.os.Build.VERSION.SDK_INT >= 26) {
builder.detectContentUriWithoutPermission();
}
StrictMode.setVmPolicy(builder.build());
}
try {
// Robolectric calls onCreate for every test, which causes problems with static members
EventBus.builder()