Skip to content

Commit

Permalink
Issue #6605 cherry-pick changes flaky test HttpOutputTest#testEmptyBu…
Browse files Browse the repository at this point in the history
…fferKnown 10.0.x branch (#6651)

* #6605 testEmptyBufferKnown: make sure the assertion does not happen before the committed flag is read

Signed-off-by: Ludovic Orban <lorban@bitronix.be>

* #6605 rename test

Signed-off-by: Ludovic Orban <lorban@bitronix.be>

Co-authored-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
olamy and lorban committed Aug 28, 2021
1 parent f10ae7c commit 4be1e63
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext;
Expand Down Expand Up @@ -838,9 +839,9 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}

@Test
public void testEmptyBufferKnown() throws Exception
public void testEmptyBufferWithZeroContentLength() throws Exception
{
FuturePromise<Boolean> committed = new FuturePromise<>();
CountDownLatch latch = new CountDownLatch(1);
AbstractHandler handler = new AbstractHandler()
{
@Override
Expand All @@ -850,7 +851,8 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
response.setStatus(200);
response.setContentLength(0);
((HttpOutput)response.getOutputStream()).write(ByteBuffer.wrap(new byte[0]));
committed.succeeded(response.isCommitted());
assertThat(response.isCommitted(), is(true));
latch.countDown();
}
};

Expand All @@ -859,7 +861,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("Content-Length: 0"));
assertThat(committed.get(10, TimeUnit.SECONDS), is(true));
assertThat(latch.await(3, TimeUnit.SECONDS), is(true));
}

@Test
Expand Down

0 comments on commit 4be1e63

Please sign in to comment.