Skip to content

Commit 44c59f0

Browse files
authored
Merge pull request #2377 from bugsnag/lemnik/okhttp-test-fix
Reduce flakes for OkHttp Instrumentation
2 parents 6ac804d + 8efa0e1 commit 44c59f0

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

features/fixtures/mazerunner/jvm-scenarios/src/main/java/com/bugsnag/android/mazerunner/scenarios/OkHttpInstrumentationScenario.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.bugsnag.android.mazerunner.scenarios
22

33
import android.content.Context
44
import android.net.Uri
5+
import android.os.StrictMode
56
import com.bugsnag.android.Configuration
67
import com.bugsnag.android.OnErrorCallback
78
import com.bugsnag.android.mazerunner.log
@@ -23,8 +24,16 @@ open class OkHttpInstrumentationScenario(
2324
eventMetadata: String?
2425
) : Scenario(config, context, eventMetadata) {
2526

26-
protected open val instrumentation
27-
get() = BugsnagOkHttp()
27+
init {
28+
// revert StrictMode to its defaults, the version of okhttp we test with trips up
29+
// StrictMode: android.os.strictmode.NonSdkApiUsedViolation:
30+
// Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setUseSessionTickets(Z)V
31+
// on some devices, and we can't reasonably fix this in the scenario
32+
StrictMode.enableDefaults()
33+
}
34+
35+
protected open val instrumentation by lazy {
36+
BugsnagOkHttp()
2837
.maxRequestBodyCapture(MAX_CAPTURE_BYTES)
2938
.maxResponseBodyCapture(MAX_CAPTURE_BYTES)
3039
.logBreadcrumbs()
@@ -35,10 +44,13 @@ open class OkHttpInstrumentationScenario(
3544
true
3645
}
3746
}
47+
}
3848

39-
private val httpClient = OkHttpClient.Builder()
40-
.addInterceptor(instrumentation.createInterceptor())
41-
.build()
49+
private val httpClient by lazy {
50+
OkHttpClient.Builder()
51+
.addInterceptor(instrumentation.createInterceptor())
52+
.build()
53+
}
4254

4355
private fun reflectionUrl(status: Int): Uri {
4456
return Uri.parse(config.endpoints.notify)

0 commit comments

Comments
 (0)