Skip to content

Commit

Permalink
Added timeouts to client, webserver and tests to identify intermitten…
Browse files Browse the repository at this point in the history
…t freezes. (#2305)

Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
  • Loading branch information
tomas-langer committed Aug 31, 2020
1 parent ac6f491 commit 99bdaac
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -45,11 +46,20 @@ class TestHttpParsingDefaults {

@BeforeAll
static void initClass() throws InterruptedException, ExecutionException, TimeoutException {
client = ClientBuilder.newClient();
client = ClientBuilder.newBuilder()
.connectTimeout(5, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.build();

ServerConfiguration serverConfig = ServerConfiguration.builder()
// a timeout of 10 seconds, to prevent infinite hangs
.timeout(10000)
.build();

webServer = WebServer.builder(Routing.builder()
.any(TestHttpParsingDefaults::handleRequest)
.build())
.config(serverConfig)
.build()
.start()
.toCompletableFuture()
Expand All @@ -71,34 +81,40 @@ static void destroyClass() throws InterruptedException, ExecutionException, Time
}

@Test
@Timeout(20)
void testOkHeader() {
testHeader(target, 8000, true);
}

@Test
@Timeout(20)
void testLongHeader() {
testHeader(target, 8900, false);
testHeader(target, 8900, false);
}

@Test
@Timeout(20)
void testOkInitialLine() {
testInitialLine(target, 10, true);
}

@Test
@Timeout(20)
void testLongInitialLine() {
// now test with big initial line
testInitialLine(target, 5000, false);
testInitialLine(target, 5000, false);
}

@Test
@Timeout(20)
void testGoodHeaderName() {
testHeaderName(target, GOOD_HEADER_NAME, true);
}

@Test
@Timeout(20)
void testBadHeaderName() {
testHeaderName(target, BAD_HEADER_NAME, false);
testHeaderName(target, BAD_HEADER_NAME, false);
Expand Down Expand Up @@ -152,6 +168,7 @@ static void testInitialLine(WebTarget target, int size, boolean success) {
response.getStatus(),
is(Http.Status.BAD_REQUEST_400.code()));
}
response.close();
}

static void testHeader(WebTarget target, int size, boolean success) {
Expand Down

0 comments on commit 99bdaac

Please sign in to comment.