Created
August 24, 2020 10:45
-
-
Save realdadfish/c7c0d8cb123c583acd3e683b68afbfa5 to your computer and use it in GitHub Desktop.
Retrofit Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.reactivex.rxjava3.core.Completable | |
import okhttp3.Interceptor | |
import okhttp3.Response | |
import okhttp3.mockwebserver.MockWebServer | |
import org.junit.Rule | |
import org.junit.Test | |
import retrofit2.Retrofit | |
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory | |
import retrofit2.http.POST | |
class RetrofitBug { | |
@get:Rule | |
val server = MockWebServer() | |
interface Service { | |
@POST("/path") | |
fun foo(): Completable | |
} | |
// exchange this with : IOException() and the test succeeds | |
class SomeException : IllegalStateException() | |
class SomeInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
if (true) { | |
throw SomeException() | |
} | |
return chain.proceed(chain.request()) | |
} | |
} | |
@Test | |
fun test() { | |
val okhttp = okhttp3.OkHttpClient.Builder() | |
.addInterceptor(SomeInterceptor()) | |
.build() | |
val retrofit = Retrofit.Builder() | |
.client(okhttp) | |
.addCallAdapterFactory(RxJava3CallAdapterFactory.create()) | |
.baseUrl(server.url("/")) | |
.build() | |
val example = retrofit.create(Service::class.java) | |
example.foo() | |
.test() | |
.await() // stalls indefinitely | |
.assertError(SomeException::class.java) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment