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 dbc0ce7 commit e738c2c
Showing 1 changed file with 6 additions and 7 deletions.
Expand Up @@ -23,7 +23,6 @@
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
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 @@ -818,7 +817,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 @@ -827,21 +826,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 testEmptyBufferKnown() throws Exception
{
AtomicBoolean committed = new AtomicBoolean();
FuturePromise<Boolean> committed = new FuturePromise<>();
AbstractHandler handler = new AbstractHandler()
{
@Override
Expand All @@ -851,7 +850,7 @@ 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.set(response.isCommitted());
committed.succeeded(response.isCommitted());
}
};

Expand All @@ -860,7 +859,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(), is(true));
assertThat(committed.get(10, TimeUnit.SECONDS), is(true));
}

@Test
Expand Down

0 comments on commit e738c2c

Please sign in to comment.