Skip to content

Commit

Permalink
Fix flaky test from #6562
Browse files Browse the repository at this point in the history
Fix flaky test from #6562

Signed-off-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
gregw committed Aug 17, 2021
1 parent 569455c commit 11507e5
Showing 1 changed file with 6 additions and 7 deletions.
Expand Up @@ -29,7 +29,6 @@
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -830,7 +829,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
@Test
public void testEmptyBuffer() throws Exception
{
AtomicBoolean committed = new AtomicBoolean();
FuturePromise<Boolean> committed = new FuturePromise<>();
AbstractHandler handler = new AbstractHandler()
{
@Override
Expand All @@ -839,21 +838,21 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
baseRequest.setHandled(true);
response.setStatus(200);
((HttpOutput)response.getOutputStream()).write(ByteBuffer.wrap(new byte[0]));
committed.set(response.isCommitted());
committed.succeeded(response.isCommitted());
}
};

_swap.setHandler(handler);
handler.start();
String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(committed.get(), is(false));
assertThat(committed.get(10, TimeUnit.SECONDS), is(false));
}

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

Expand All @@ -873,7 +872,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(latch.await(3, TimeUnit.SECONDS), is(true));
assertThat(committed.get(10, TimeUnit.SECONDS), is(true));
}

@Test
Expand Down

0 comments on commit 11507e5

Please sign in to comment.