Skip to content

Commit 7c0ffb2

Browse files
committed
Fixed flaky test.
Signed-off-by: Simone Bordet <[email protected]> (cherry picked from commit 6cd5a05) Signed-off-by: Simone Bordet <[email protected]>
1 parent 959bdfa commit 7c0ffb2

File tree

1 file changed

+17
-3
lines changed
  • jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport

1 file changed

+17
-3
lines changed

jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport/HttpClientTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,26 @@ public boolean handle(Request request, org.eclipse.jetty.server.Response respons
12351235
}
12361236
});
12371237

1238-
ContentResponse response = client.newRequest(newURI(transportType))
1238+
CountDownLatch resultLatch = new CountDownLatch(1);
1239+
AtomicReference<Response> responseRef = new AtomicReference<>();
1240+
client.newRequest(newURI(transportType))
12391241
.headers(h -> h.put(HttpHeader.EXPECT, "Invalid"))
1242+
// Body is necessary, otherwise the Expect header is removed.
12401243
.body(new StringRequestContent("hello"))
1241-
.timeout(5, TimeUnit.SECONDS)
1242-
.send();
1244+
.onResponseHeaders(responseRef::set)
1245+
.send(r -> resultLatch.countDown());
1246+
1247+
// In HTTP/2, the request body is not read, as the error response
1248+
// is sent without calling the Handler, so a reset is triggered
1249+
// after the response is sent.
1250+
// The test verifies that the right response is received at the
1251+
// "headers" event, because the response body is read asynchronously
1252+
// and may be dropped when the RST_STREAM frame is received.
1253+
// Waiting for the "complete" event will likely result in a failure
1254+
// due to the RST_STREAM being received.
12431255

1256+
assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
1257+
Response response = responseRef.get();
12441258
assertThat(response.getStatus(), equalTo(HttpStatus.EXPECTATION_FAILED_417));
12451259
}
12461260

0 commit comments

Comments
 (0)