Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test from #6562/#6563 #6628

Merged
merged 2 commits into from Aug 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,9 +27,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.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -830,7 +828,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 +837,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 @@ -863,8 +861,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]));
assertThat(response.isCommitted(), is(true));
latch.countDown();
committed.succeeded(response.isCommitted());
gregw marked this conversation as resolved.
Show resolved Hide resolved
}
};

Expand All @@ -873,7 +870,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