From 25a95b83f91c9fdd65bd8c528e45e061b58286db Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 2 Feb 2017 19:28:16 -0700 Subject: [PATCH] Bad tests take too long --- .../jetty/server/AbstractHttpTest.java | 3 +- .../server/HttpManyWaysToCommitTest.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index 736f0835a48..b350d58bfe9 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -92,7 +92,8 @@ public abstract class AbstractHttpTest writer.write("\r\n"); writer.flush(); - HttpTester.Response response = HttpTester.parseResponse(socket.getInputStream()); + HttpTester.Input input = HttpTester.from(socket.getInputStream()); + HttpTester.Response response = HttpTester.parseResponse(input); if ("HTTP/1.1".equals(httpVersion) && response.get("content-length") == null && response.get("transfer-encoding") == null diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java index 37b410b26c2..c5e60c4b34a 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java @@ -417,6 +417,47 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } } + @Test + public void testSetContentLengthFlushAndWriteInsufficientBytes() throws Exception + { + server.setHandler(new SetContentLengthAndWriteInsufficientBytesHandler(true)); + server.start(); + try + { + HttpTester.Response response = executeRequest(); + char badChar = (char) -1; + String failed_body = "" + badChar + badChar + badChar; + assertThat("response code", response.getStatus(), is(200)); + assertHeader(response, "content-length", "6"); + assertThat(response.getContent(), endsWith(failed_body)); + } + catch(EOFException e) + { + // possible good response + } + } + + @Test + public void testSetContentLengthAndWriteInsufficientBytes() throws Exception + { + server.setHandler(new SetContentLengthAndWriteInsufficientBytesHandler(false)); + server.start(); + + try + { + HttpTester.Response response = executeRequest(); + char badChar = (char) -1; + String failed_body = "" + badChar + badChar + badChar; + assertThat("response code is 200", response.getStatus(), is(200)); + assertHeader(response, "content-length", "6"); + assertThat(response.getContent(), endsWith(failed_body)); + } + catch(EOFException e) + { + // expected + } + } + @Test public void testSetContentLengthAndWriteExactlyThatAmountOfBytes() throws Exception {