#6327 wait for the request to be committed before sending the data

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2021-08-04 10:57:09 +02:00
parent 72505af846
commit 0a98a37cb6
1 changed files with 7 additions and 14 deletions

View File

@ -678,29 +678,22 @@ public class HttpClientStreamTest extends AbstractTest<TransportScenario>
}
});
CountDownLatch demandLatch = new CountDownLatch(2);
CountDownLatch requestLatch = new CountDownLatch(1);
try (AsyncRequestContent content = new AsyncRequestContent()
{
@Override
public void demand()
{
demandLatch.countDown();
super.demand();
}
})
CountDownLatch requestSentLatch = new CountDownLatch(1);
CountDownLatch responseLatch = new CountDownLatch(1);
try (AsyncRequestContent content = new AsyncRequestContent())
{
scenario.client.newRequest(scenario.newURI())
.scheme(scenario.getScheme())
.body(content)
.onRequestCommit((request) -> requestSentLatch.countDown())
.send(result ->
{
if (result.isSucceeded() && result.getResponse().getStatus() == 200)
requestLatch.countDown();
responseLatch.countDown();
});
// Make sure we provide the content *after* the request has been "sent".
assertTrue(demandLatch.await(5, TimeUnit.SECONDS));
assertTrue(requestSentLatch.await(5, TimeUnit.SECONDS));
try (ByteArrayInputStream input = new ByteArrayInputStream(new byte[1024]))
{
@ -712,7 +705,7 @@ public class HttpClientStreamTest extends AbstractTest<TransportScenario>
}
}
}
assertTrue(requestLatch.await(5, TimeUnit.SECONDS));
assertTrue(responseLatch.await(5, TimeUnit.SECONDS));
}
@ParameterizedTest