From 7c775f891ed920e20c0d56a8d889aedf8e3406d7 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Tue, 8 Aug 2023 15:49:10 +0200 Subject: [PATCH] Speed up tests --- .../appleTest/kotlin/test/HttpEngineTest.kt | 22 +++++++------------ .../kotlin/benchmarks/BenchmarksTest.kt | 8 ++++--- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/tests/integration-tests/src/appleTest/kotlin/test/HttpEngineTest.kt b/tests/integration-tests/src/appleTest/kotlin/test/HttpEngineTest.kt index 9b2f5c1c14d..de877c5585a 100644 --- a/tests/integration-tests/src/appleTest/kotlin/test/HttpEngineTest.kt +++ b/tests/integration-tests/src/appleTest/kotlin/test/HttpEngineTest.kt @@ -9,11 +9,8 @@ import com.apollographql.apollo3.mpp.currentTimeMillis import com.apollographql.apollo3.network.http.DefaultHttpEngine import com.apollographql.apollo3.network.http.get import com.apollographql.apollo3.testing.internal.runTest -import platform.CFNetwork.kCFErrorDomainCFNetwork -import platform.CFNetwork.kCFErrorHTTPSProxyConnectionFailure -import platform.Foundation.CFBridgingRelease import platform.Foundation.NSError -import platform.Foundation.NSURLErrorCannotFindHost +import platform.Foundation.NSURLErrorCannotConnectToHost import platform.Foundation.NSURLErrorDomain import platform.Foundation.NSURLErrorTimedOut import kotlin.test.Test @@ -26,7 +23,11 @@ import kotlin.test.fail class HttpEngineTest { @Test fun canReadNSError() = runTest { - val apolloClient = ApolloClient.Builder().serverUrl("https://inexistent.host/graphql").build() + /** + * Try to trigger an error wihtout having to wait 60s on a timeout. + * Hopefully Port 1 is closed on most machines. If that's not enough, we'd need to find an instrumented server + */ + val apolloClient = ApolloClient.Builder().serverUrl("https://127.0.0.1:1/graphql").build() val response = apolloClient.query(HeroNameQuery()).execute() val apolloNetworkException = response.exception @@ -38,15 +39,8 @@ class HttpEngineTest { // assertIs(cause) check(cause is NSError) - assertTrue( - when { - // Happens locally if a proxy is running - cause.domain == (CFBridgingRelease(kCFErrorDomainCFNetwork) as String) && cause.code == kCFErrorHTTPSProxyConnectionFailure.toLong() -> true - // Default case - cause.domain == NSURLErrorDomain && cause.code == NSURLErrorCannotFindHost -> true - else -> false - } - ) + assertEquals(cause.domain, NSURLErrorDomain) + assertEquals(cause.code, NSURLErrorCannotConnectToHost) } @Test diff --git a/tests/native-benchmarks/src/appleTest/kotlin/benchmarks/BenchmarksTest.kt b/tests/native-benchmarks/src/appleTest/kotlin/benchmarks/BenchmarksTest.kt index 3db085204d7..bccb83dfae5 100644 --- a/tests/native-benchmarks/src/appleTest/kotlin/benchmarks/BenchmarksTest.kt +++ b/tests/native-benchmarks/src/appleTest/kotlin/benchmarks/BenchmarksTest.kt @@ -25,7 +25,9 @@ class BenchmarksTest { repeat(MEASUREMENT_COUNT) { durations.add( measureTime { - repeat(EXECUTION_PER_MEASUREMENT) { test(it) } + repeat(EXECUTION_PER_MEASUREMENT) { + test(it) + } } ) } @@ -83,8 +85,8 @@ class BenchmarksTest { ) companion object { - private const val EXECUTION_PER_MEASUREMENT = 500 - private const val MEASUREMENT_COUNT = 10 + private const val EXECUTION_PER_MEASUREMENT = 100 + private const val MEASUREMENT_COUNT = 4 val measurements = mutableListOf()