Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw committed Mar 7, 2024
1 parent a2e6eb0 commit 18b9a44
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions mobile/test/java/integration/AndroidEnvoyExplicitFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ public void get_withThrottledBodyResponse_bufferLargerThanResponseBody() throws
assertThat(response.getBodyAsString()).isEqualTo("hello, world");
assertThat(response.getEnvoyError()).isNull();
// A "terminating" empty buffer is systematically sent through the setOnResponseData callback.
// See: https://github.com/envoyproxy/envoy-mobile/issues/1393
assertThat(response.getNbResponseChunks()).isEqualTo(4); // 5 bytes, 5 bytes, 2, and 0 bytes
assertThat(response.getNbResponseChunks()).isEqualTo(3); // 5 bytes, 5 bytes, 2
}

@Test
Expand All @@ -286,8 +285,7 @@ public void get_withThrottledBodyResponse_bufferSmallerThanResponseBody() throws
assertThat(response.getBodyAsString()).isEqualTo("hello, world");
assertThat(response.getEnvoyError()).isNull();
// A "terminating" empty buffer is systematically sent through the setOnResponseData callback.
// See: https://github.com/envoyproxy/envoy-mobile/issues/1393
assertThat(response.getNbResponseChunks()).isEqualTo(6); // 3&2 bytes, 3&2 bytes, 2, and 0 bytes
assertThat(response.getNbResponseChunks()).isEqualTo(5); // 3&2 bytes, 3&2 bytes, 2
}

@Test
Expand Down Expand Up @@ -487,17 +485,21 @@ private Response sendRequest(RequestScenario requestScenario) throws Exception {
return null;
})
.setOnResponseData((data, endStream, streamIntel) -> {
response.get().addBody(ByteBuffers.copy(data));
response.get().addStreamIntel(streamIntel);
if (!endStream) {
if (requestScenario.waitOnReadData) {
try {
Thread.sleep(100 + (int)(Math.random() * 50));
} catch (InterruptedException e) {
// Don't care
// Ignore when the data is empty.
// See: https://github.com/envoyproxy/envoy-mobile/issues/1393
if (data.hasRemaining()) {
response.get().addBody(ByteBuffers.copy(data));
response.get().addStreamIntel(streamIntel);
if (!endStream) {
if (requestScenario.waitOnReadData) {
try {
Thread.sleep(100 + (int)(Math.random() * 50));
} catch (InterruptedException e) {
// Don't care
}
}
streamRef.get().readData(requestScenario.responseBufferSize);
}
streamRef.get().readData(requestScenario.responseBufferSize);
}
return null;
})
Expand Down

0 comments on commit 18b9a44

Please sign in to comment.