File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
okhttp-testing-support/src/main/kotlin/okhttp3/internal/http
main/kotlin/okhttp3/internal/connection Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,8 @@ import okhttp3.internal.format
3030class RecordingProxySelector : ProxySelector () {
3131 @JvmField val proxies = mutableListOf<Proxy >()
3232
33- private val requestedUris = mutableListOf<URI >()
34- private val failures = mutableListOf<String >()
33+ val requestedUris = mutableListOf<URI >()
34+ val failures = mutableListOf<String >()
3535
3636 override fun select (uri : URI ): List <Proxy > {
3737 requestedUris.add(uri)
Original file line number Diff line number Diff line change @@ -141,6 +141,14 @@ class ConnectPlan(
141141 success = true
142142 return ConnectResult (plan = this )
143143 } catch (e: IOException ) {
144+ // If we used the ProxySelector, and got a IOException during connect, report the failure.
145+ if (route.address.proxy == null && route.proxy.type() != Proxy .Type .DIRECT ) {
146+ route.address.proxySelector.connectFailed(
147+ route.address.url.toUri(),
148+ route.proxy.address(),
149+ e,
150+ )
151+ }
144152 user.connectFailed(route, null , e)
145153 return ConnectResult (plan = this , throwable = e)
146154 } finally {
Original file line number Diff line number Diff line change 1515 */
1616package okhttp3
1717
18+ import assertk.all
1819import assertk.assertThat
1920import assertk.assertions.contains
2021import assertk.assertions.containsExactly
2122import assertk.assertions.doesNotContain
2223import assertk.assertions.hasMessage
24+ import assertk.assertions.hasSize
25+ import assertk.assertions.index
2326import assertk.assertions.isCloseTo
2427import assertk.assertions.isEmpty
2528import assertk.assertions.isEqualTo
@@ -30,6 +33,7 @@ import assertk.assertions.isNotNull
3033import assertk.assertions.isNotSameAs
3134import assertk.assertions.isNull
3235import assertk.assertions.isTrue
36+ import assertk.assertions.matches
3337import assertk.assertions.startsWith
3438import assertk.fail
3539import java.io.FileNotFoundException
@@ -1017,6 +1021,12 @@ open class CallTest {
10171021 executeSynchronously(request)
10181022 .assertCode(200 )
10191023 .assertBody(" success!" )
1024+
1025+ assertThat(proxySelector.failures)
1026+ .all {
1027+ hasSize(1 )
1028+ index(0 ).matches(" .* Connect timed out" .toRegex(RegexOption .IGNORE_CASE ))
1029+ }
10201030 }
10211031
10221032 /* * https://github.com/square/okhttp/issues/4875 */
You can’t perform that action at this time.
0 commit comments