MockWebServer timeout issues
See original GitHub issueMockWebServer timeout issue
Since I have upgraded from 3.2.0
to 3.3.1
, our CI has timed out while using the MockWebServer
.
Code:
The test case is similar to: https://github.com/JakeWharton/retrofit1-okhttp3-client/blob/master/src/test/java/com/jakewharton/retrofit/Ok3ClientIntegrationTest.java#L23.
public final class ServiceTest {
@Rule public final MockWebServer server = new MockWebServer();
protected String mockEndPoint;
@Before
public void setUp() throws Exception {
mockEndPoint = server.url("/").toString();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testAcquireToken() {
// Response
final String mockResponse = "{\n" +
" \"access_token\": \"" + TOKEN_VALID + "\",\n" +
" \"refresh_token\": \"" + TOKEN_VALID + "\",\n" +
" \"token_type\": \"bearer\",\n" +
" \"expires_in\": 3600,\n" +
" \"logout_token\": \"r0ZZSZDVbUma9sTz0ZXduwvic1V7RdSIZMe\\/ysHTY8s=\"\n" +
"}";
server.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(mockResponse));
// Request
final Map<String, String> formData = new HashMap<>();
formData.put("grant_type", "password");
formData.put("client_id", "fake-id");
formData.put("client_secret", "fake-secret");
formData.put("username", "user EMAIL");
formData.put("password", "user PASSWORD");
final TokenResponse response = Service.getInstance(mockEndPoint)
.acquireToken(formData)
.toBlocking()
.first();
assertThat(response.getAccessToken()).isEqualTo("valid");
}
}
Error:
19:44:09 <>Test > testAcquireToken STANDARD_ERROR
19:44:09 Jun 10, 2016 12:45:41 PM okhttp3.mockwebserver.MockWebServer$3 execute
19:44:09 INFO: MockWebServer[63326] starting to accept connections
19:44:09 Jun 10, 2016 12:45:41 PM okhttp3.mockwebserver.MockWebServer$4 processOneRequest
19:44:09 INFO: MockWebServer[63326] received request: POST /auth/v1/token HTTP/1.1 and responded: HTTP/1.1 200 OK
19:44:09 Jun 10, 2016 12:45:41 PM okhttp3.mockwebserver.MockWebServer$3 acceptConnections
19:44:09 INFO: MockWebServer[63326] done accepting connections: Socket closed
20:09:59 Build timed out (after 30 minutes). Marking the build as failed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
MockWebServer shuts down after timeout · Issue #6976 - GitHub
I think I encountered a bug. I wrote a custom retry handler, and I wanted to write a test for it. For the...
Read more >MockWebServer response delay - testing timeouts
I'm trying to test HTTP timeout scenarios using a MockWebServer which answers my test requests sent with Retrofit/OkHttp.
Read more >Better Integration Testing with MockWebServer - Industrial Logic
One challenge is that if there is any problem with your test setup or mocks you are likely to get a blocking timeout...
Read more >okhttp3.mockwebserver.SocketPolicy Java Examples
This page shows Java code examples of okhttp3.mockwebserver. ... The test sets a read timeout of 0.25 s and the mock * server...
Read more >How to Test Latency with a Mock Server in Java - Nick Fisher
All we do here is assert that we're getting a read timeout when the timeout is lower than how long our mock server...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awww, that’s awkward. We’ve seen other problems with Robolectric, mostly around how OkHttp attempts to detect which platform it’s running on. Robolectric makes that very difficult because it looks like Android and the JVM simultaneously.
After playing with the dependencies, it seems that rolling back Robolectric to
3.1-rc1
from3.1
seems to work fine: