23
23
import feign .client .AbstractClientTest ;
24
24
import feign .Feign ;
25
25
import java .util .Collections ;
26
+ import java .util .concurrent .TimeUnit ;
26
27
import okhttp3 .mockwebserver .MockResponse ;
27
28
import org .assertj .core .data .MapEntry ;
28
29
import org .junit .Test ;
@@ -60,9 +61,14 @@ public void testContentTypeWithoutCharset() throws Exception {
60
61
public void testNoFollowRedirect () throws Exception {
61
62
server .enqueue (
62
63
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" ));
63
67
64
68
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 (new Request .Options (10_000 , TimeUnit .MILLISECONDS , 10_000 , TimeUnit .MILLISECONDS ,
71
+ false ))
66
72
.target (OkHttpClientTestInterface .class , "http://localhost:" + server .getPort ());
67
73
68
74
Response response = api .get ();
@@ -83,7 +89,9 @@ public void testFollowRedirect() throws Exception {
83
89
server .enqueue (new MockResponse ().setBody (expectedBody ));
84
90
85
91
OkHttpClientTestInterface api = newBuilder ()
86
- .options (new Request .Options (1000 , 1000 , true ))
92
+ // Use the same connect and read timeouts as the OkHttp default
93
+ .options (new Request .Options (10_000 , TimeUnit .MILLISECONDS , 10_000 , TimeUnit .MILLISECONDS ,
94
+ true ))
87
95
.target (OkHttpClientTestInterface .class , "http://localhost:" + server .getPort ());
88
96
89
97
Response response = api .get ();
0 commit comments