Issue #6605 cherry-pick changes flaky test HttpOutputTest#testEmptyBufferKnown 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>
This commit is contained in:
Olivier Lamy 2021-08-28 19:28:02 +10:00 committed by GitHub
parent f10ae7c955
commit 4be1e63bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
@ -838,9 +839,9 @@ public class HttpOutputTest
} }
@Test @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() AbstractHandler handler = new AbstractHandler()
{ {
@Override @Override
@ -850,7 +851,8 @@ public class HttpOutputTest
response.setStatus(200); response.setStatus(200);
response.setContentLength(0); response.setContentLength(0);
((HttpOutput)response.getOutputStream()).write(ByteBuffer.wrap(new byte[0])); ((HttpOutput)response.getOutputStream()).write(ByteBuffer.wrap(new byte[0]));
committed.succeeded(response.isCommitted()); assertThat(response.isCommitted(), is(true));
latch.countDown();
} }
}; };
@ -859,7 +861,7 @@ public class HttpOutputTest
String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n"); String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n");
assertThat(response, containsString("HTTP/1.1 200 OK")); assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("Content-Length: 0")); assertThat(response, containsString("Content-Length: 0"));
assertThat(committed.get(10, TimeUnit.SECONDS), is(true)); assertThat(latch.await(3, TimeUnit.SECONDS), is(true));
} }
@Test @Test