* Issue #8822 - NPE on deflater.reset() called after deflater.end() Now waiting for the server to finish writing even in case of HEAD method, otherwise the test exit races with the server finishing to fake-write the response content. Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
051588d45b
commit
34e38d2156
|
@ -18,6 +18,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -29,7 +30,9 @@ import org.eclipse.jetty.http.DateGenerator;
|
|||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.LocalConnector;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
|
||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||
|
@ -53,6 +56,7 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Test the GzipHandler support when working with the {@link DefaultServlet}.
|
||||
|
@ -78,6 +82,17 @@ public class GzipDefaultServletTest extends AbstractGzipTest
|
|||
LocalConnector localConnector = new LocalConnector(server);
|
||||
server.addConnector(localConnector);
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
localConnector.addBean(new HttpChannel.Listener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Request request)
|
||||
{
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
Path contextDir = workDir.resolve("context");
|
||||
FS.ensureDirExists(contextDir);
|
||||
|
||||
|
@ -122,6 +137,10 @@ public class GzipDefaultServletTest extends AbstractGzipTest
|
|||
assertThat("Response[ETag]", response.get("ETag"), containsString(CompressedContentFormat.GZIP.getEtagSuffix()));
|
||||
|
||||
assertThat("Response[Content-Length]", response.get("Content-Length"), is(nullValue()));
|
||||
|
||||
// allow server to finish sending body (for HEAD, server.stop() races with the gzip writing thread)
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
|
||||
// A HEAD request should have similar headers, but no body
|
||||
if (!method.equals("HEAD"))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue