diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d51f05c17..6f281eeab 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -231,30 +231,6 @@ libs database schema: # # once these prove stable, the task should be switched to # connectedCheck to test all the build flavors -.connected-template: &connected-template - extends: .base - script: - - ./gradlew assembleFullDebug - - export AVD_SDK=`echo $CI_JOB_NAME | awk '{print $2}'` - - export AVD_TAG=`echo $CI_JOB_NAME | awk '{print $3}'` - - export AVD_ARCH=`echo $CI_JOB_NAME | awk '{print $4}'` - - export AVD_PACKAGE="system-images;android-${AVD_SDK};${AVD_TAG};${AVD_ARCH}" - - echo $AVD_PACKAGE - - - ls -l ~/.android - - - adb start-server - - start-emulator - - wait-for-emulator - - adb devices - - adb shell input keyevent 82 & - - ./gradlew installFullDebug - - adb shell am start -n org.fdroid.fdroid.debug/org.fdroid.fdroid.views.main.MainActivity - - if [ $AVD_SDK -lt 29 ] || ! emulator -accel-check; then - export FLAG=-Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest; - fi - - ./gradlew connectedFullDebugAndroidTest $FLAG - .kvm-connected-template: &kvm-connected-template extends: .base image: briar/ci-image-android-emulator:latest @@ -277,10 +253,10 @@ libs database schema: - start-emulator.sh - ./gradlew installFullDebug - adb shell am start -n org.fdroid.fdroid.debug/org.fdroid.fdroid.views.main.MainActivity - - if [ $AVD_SDK -lt 29 ] || ! emulator -accel-check; then - export FLAG=-Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest; - fi - - ./gradlew :app:connectedFullDebugAndroidTest :libs:database:connectedCheck :libs:download:connectedCheck :libs:index:connectedCheck $FLAG + - export FLAG="-Pandroid.testInstrumentationRunnerArguments.notAnnotation=androidx.test.filters.LargeTest,androidx.test.filters.FlakyTest" + - ./gradlew $FLAG :app:connectedFullDebugAndroidTest :libs:database:connectedCheck :libs:download:connectedCheck :libs:index:connectedCheck + - export FLAG="-Pandroid.testInstrumentationRunnerArguments.annotation=androidx.test.filters.FlakyTest" + - for i in {1..5}; do echo "$i" && ./gradlew $FLAG :app:connectedFullDebugAndroidTest :libs:database:connectedCheck :libs:download:connectedCheck :libs:index:connectedCheck && break; done # Since jobs that require KVM need special runners, these jobs are @@ -311,9 +287,9 @@ kvm jobs skipped: kvm 23 default x86: - <<: *test-template <<: *kvm-template + pages: extends: .base stage: deploy diff --git a/app/src/androidTest/java/org/fdroid/fdroid/net/HttpDownloaderTest.java b/app/src/androidTest/java/org/fdroid/fdroid/net/HttpDownloaderTest.java index 2b9766d6a..6e4e4bf31 100644 --- a/app/src/androidTest/java/org/fdroid/fdroid/net/HttpDownloaderTest.java +++ b/app/src/androidTest/java/org/fdroid/fdroid/net/HttpDownloaderTest.java @@ -8,6 +8,7 @@ import android.os.Build; import android.util.Log; import androidx.core.util.Pair; +import androidx.test.filters.FlakyTest; import org.fdroid.download.DownloadRequest; import org.fdroid.download.HttpDownloader; @@ -29,6 +30,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +@FlakyTest public class HttpDownloaderTest { private static final String TAG = "HttpDownloaderTest"; diff --git a/libs/download/src/androidInstrumentedTest/kotlin/org/fdroid/download/HttpManagerInstrumentationTest.kt b/libs/download/src/androidInstrumentedTest/kotlin/org/fdroid/download/HttpManagerInstrumentationTest.kt index e41367bb6..233979620 100644 --- a/libs/download/src/androidInstrumentedTest/kotlin/org/fdroid/download/HttpManagerInstrumentationTest.kt +++ b/libs/download/src/androidInstrumentedTest/kotlin/org/fdroid/download/HttpManagerInstrumentationTest.kt @@ -1,7 +1,9 @@ package org.fdroid.download import android.os.Build.VERSION.SDK_INT +import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.FlakyTest import io.ktor.client.engine.HttpClientEngine import io.ktor.client.engine.HttpClientEngineFactory import io.ktor.client.engine.okhttp.OkHttp @@ -22,7 +24,9 @@ import javax.net.ssl.SSLHandshakeException import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse +import kotlin.test.fail +@FlakyTest @RunWith(AndroidJUnit4::class) @Suppress("BlockingMethodInNonBlockingContext") internal class HttpManagerInstrumentationTest { @@ -31,11 +35,29 @@ internal class HttpManagerInstrumentationTest { @Test fun testCleartext() = runSuspend { - val httpManager = HttpManager(userAgent, null) - val mirror = Mirror("http://neverssl.com") - val downloadRequest = DownloadRequest("/", listOf(mirror)) + suspend fun noSsl(url: String) { + val httpManager = HttpManager(userAgent, null) + val mirror = Mirror(url) + val downloadRequest = DownloadRequest("/", listOf(mirror)) - httpManager.getBytes(downloadRequest) + httpManager.getBytes(downloadRequest) + } + // try different services in case one is down + listOf( + "http://http.badssl.com/", + "http://neverssl.com", + "http://httpforever.com/", + ).forEach { url -> + Log.i("HttpManagerInstrumentationTest", "Testing $url") + try { + noSsl(url) + Log.i("HttpManagerInstrumentationTest", "Success $url") + return@runSuspend // success + } catch (e: Exception) { + Log.e("HttpManagerInstrumentationTest", "Error $url ", e) + } + } + fail("All no-SSL domains failed.") } @Test(expected = SSLHandshakeException::class) diff --git a/libs/download/src/androidInstrumentedTest/res/xml/network_security_config.xml b/libs/download/src/androidInstrumentedTest/res/xml/network_security_config.xml index f8bde03c6..0f449adfa 100644 --- a/libs/download/src/androidInstrumentedTest/res/xml/network_security_config.xml +++ b/libs/download/src/androidInstrumentedTest/res/xml/network_security_config.xml @@ -1,6 +1,8 @@ + http.badssl.com neverssl.com + httpforever.com