2323import feign .client .AbstractClientTest ;
2424import feign .Feign ;
2525import java .util .Collections ;
26+ import java .util .concurrent .TimeUnit ;
2627import okhttp3 .mockwebserver .MockResponse ;
2728import org .assertj .core .data .MapEntry ;
2829import org .junit .Test ;
@@ -60,9 +61,15 @@ public void testContentTypeWithoutCharset() throws Exception {
6061 public void testNoFollowRedirect () throws Exception {
6162 server .enqueue (
6263 new MockResponse ().setResponseCode (302 ).addHeader ("Location" , server .url ("redirect" )));
64+ // Enqueue a response to fail fast if the redirect is followed, instead of waiting for the
65+ // timeout
66+ server .enqueue (new MockResponse ().setBody ("Hello" ));
6367
6468 OkHttpClientTestInterface api = newBuilder ()
65- .options (new Request .Options (1000 , 1000 , false ))
69+ // Use the same connect and read timeouts as the OkHttp default
70+ .options (
71+ new Request .Options (10_000 , TimeUnit .MILLISECONDS , 10_000 , TimeUnit .MILLISECONDS ,
72+ false ))
6673 .target (OkHttpClientTestInterface .class , "http://localhost:" + server .getPort ());
6774
6875 Response response = api .get ();
@@ -83,7 +90,9 @@ public void testFollowRedirect() throws Exception {
8390 server .enqueue (new MockResponse ().setBody (expectedBody ));
8491
8592 OkHttpClientTestInterface api = newBuilder ()
86- .options (new Request .Options (1000 , 1000 , true ))
93+ // Use the same connect and read timeouts as the OkHttp default
94+ .options (
95+ new Request .Options (10_000 , TimeUnit .MILLISECONDS , 10_000 , TimeUnit .MILLISECONDS , true ))
8796 .target (OkHttpClientTestInterface .class , "http://localhost:" + server .getPort ());
8897
8998 Response response = api .get ();
0 commit comments