Skip to content

Commit

Permalink
fix flaky test CallTest.legalToExecuteTwiceCloning_Async
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored and squarejesse committed Aug 28, 2016
1 parent 65a1134 commit 5f26982
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions okhttp-tests/src/test/java/okhttp3/CallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -605,8 +607,15 @@ private void postBodyRetransmittedAfterAuthorizationFail(String body) throws Exc
Call cloned = call.clone();
cloned.enqueue(callback);

callback.await(request.url()).assertBody("abc");
callback.await(request.url()).assertBody("def");
RecordedResponse firstResponse = callback.await(request.url()).assertSuccessful();
RecordedResponse secondResponse = callback.await(request.url()).assertSuccessful();

Set<String> bodies = new LinkedHashSet<>();
bodies.add(firstResponse.getBody());
bodies.add(secondResponse.getBody());

assertTrue(bodies.contains("abc"));
assertTrue(bodies.contains("def"));
}

@Test public void get_Async() throws Exception {
Expand Down Expand Up @@ -2286,8 +2295,8 @@ private InetSocketAddress startNullServer() throws IOException {
}

/**
* OkHttp has a bug where a `Connection: close` response header is not honored when establishing
* a TLS tunnel. https://github.com/square/okhttp/issues/2426
* OkHttp has a bug where a `Connection: close` response header is not honored when establishing a
* TLS tunnel. https://github.com/square/okhttp/issues/2426
*/
@Test public void proxyAuthenticateOnConnectWithConnectionClose() throws Exception {
server.useHttps(sslClient.socketFactory, true);
Expand Down
4 changes: 4 additions & 0 deletions okhttp-tests/src/test/java/okhttp3/RecordedResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,8 @@ private void assertDateInRange(long minimum, long actual, long maximum) {
private String format(long time) {
return new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(time));
}

public String getBody() {
return body;
}
}

0 comments on commit 5f26982

Please sign in to comment.