From 3ba82718881394e165981f1cce421c42752006d9 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 20 Jan 2024 12:43:34 +0000 Subject: [PATCH 1/2] Minimise HttpOverHttp2Test flakes --- .../internal/http2/HttpOverHttp2Test.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt b/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt index 2b788c07580f..b5a6d53d22f5 100644 --- a/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt +++ b/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt @@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicReference import javax.net.ssl.SSLException +import kotlin.io.use import kotlin.test.assertFailsWith import mockwebserver3.Dispatcher import mockwebserver3.MockResponse @@ -83,10 +84,9 @@ import okhttp3.internal.discard import okhttp3.testing.Flaky import okhttp3.testing.PlatformRule import okhttp3.tls.HandshakeCertificates -import okio.Buffer -import okio.BufferedSink -import okio.GzipSink -import okio.buffer +import okio.* +import okio.Path.Companion.toPath +import okio.fakefilesystem.FakeFileSystem import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertArrayEquals import org.junit.jupiter.api.Assumptions.assumeTrue @@ -107,9 +107,6 @@ class HttpOverHttp2Test { override fun arguments() = listOf(Protocol.H2_PRIOR_KNOWLEDGE, Protocol.HTTP_2) } - @TempDir - lateinit var tempDir: File - @RegisterExtension val platform: PlatformRule = PlatformRule() @@ -127,7 +124,8 @@ class HttpOverHttp2Test { private lateinit var server: MockWebServer private lateinit var protocol: Protocol private lateinit var client: OkHttpClient - private lateinit var cache: Cache + private val fileSystem: FakeFileSystem = FakeFileSystem() + private val cache: Cache = Cache("/tmp/cache".toPath(), Long.MAX_VALUE, fileSystem) private lateinit var scheme: String private fun configureClientTestRule(): OkHttpClientTestRule { @@ -164,10 +162,13 @@ class HttpOverHttp2Test { .build() scheme = "http" } - cache = Cache(tempDir, Int.MAX_VALUE.toLong()) } @AfterEach fun tearDown() { +// TODO reenable after https://github.com/square/okhttp/issues/8206 +// fileSystem.checkNoOpenFiles() + cache.close() + java.net.Authenticator.setDefault(null) } From ab076ef46d09f3c24f570d747c2b0deed8b7d276 Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sat, 20 Jan 2024 12:45:16 +0000 Subject: [PATCH 2/2] Minimise HttpOverHttp2Test flakes --- .../test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt b/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt index b5a6d53d22f5..4c1f4b795171 100644 --- a/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt +++ b/okhttp/src/test/java/okhttp3/internal/http2/HttpOverHttp2Test.kt @@ -24,7 +24,6 @@ import assertk.assertions.isFalse import assertk.assertions.isNull import assertk.assertions.isTrue import assertk.fail -import java.io.File import java.io.IOException import java.net.HttpURLConnection import java.net.SocketTimeoutException @@ -39,7 +38,6 @@ import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicReference import javax.net.ssl.SSLException -import kotlin.io.use import kotlin.test.assertFailsWith import mockwebserver3.Dispatcher import mockwebserver3.MockResponse @@ -84,8 +82,11 @@ import okhttp3.internal.discard import okhttp3.testing.Flaky import okhttp3.testing.PlatformRule import okhttp3.tls.HandshakeCertificates -import okio.* +import okio.Buffer +import okio.BufferedSink +import okio.GzipSink import okio.Path.Companion.toPath +import okio.buffer import okio.fakefilesystem.FakeFileSystem import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertArrayEquals @@ -94,7 +95,6 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Timeout import org.junit.jupiter.api.extension.RegisterExtension -import org.junit.jupiter.api.io.TempDir import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource