Skip to content

Commit

Permalink
Updates test after further testing on Linux.
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
  • Loading branch information
spericas committed Aug 23, 2024
1 parent f02ea09 commit fb5cfa5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ default int maxUpgradeContentLength() {
}

/**
* Timeout millis after which any idle connection will be automatically closed
* Timeout seconds after which any idle connection will be automatically closed
* by the server.
*
* @return idle connection timeout in seconds
Expand Down Expand Up @@ -598,7 +598,7 @@ default B tls(Supplier<WebServerTls> tlsConfig) {
B trustedProxies(AllowList trustedProxies);

/**
* Sets the number of millis after which an idle connection will be automatically
* Sets the number of seconds after which an idle connection will be automatically
* closed by the server.
*
* @param seconds time in seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.net.SocketException;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Logger;

import io.helidon.common.http.Http;
Expand All @@ -28,9 +27,9 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Tests support for idle connection timeouts.
Expand Down Expand Up @@ -84,33 +83,26 @@ public void testIdleConnectionClosed() throws Exception {
String res = client.receive();
assertThat(res, containsString("Hello World!"));

// second request while connection is active
client.request(Http.Method.GET,
"/hello",
null);
res = client.receive();
assertThat(res, containsString("Hello World!"));

// wait for connection to time out due to inactivity
Thread.sleep(2 * IDLE_TIMEOUT);

// now fail attempting to use connection again
assertEventuallyThrows(SocketException.class, () -> {
client.request(Http.Method.GET,
"/hello",
null);
client.receive();
return null;
}, 5 * IDLE_TIMEOUT);
}
}

private static void assertEventuallyThrows(Class<?> exc, Callable<?> runnable, long millis)
throws InterruptedException {
long start = System.currentTimeMillis();
do {
// try again and either get nothing or an exception
try {
runnable.call();
} catch (Throwable t) {
if (t.getClass().equals(exc)) {
return;
}
client.request(Http.Method.GET,
"/hello",
null);
res = client.receive();
assertThat(res, is(""));
} catch (SocketException e) {
// falls through as possible outcome
}
Thread.sleep(millis / 3);
} while (System.currentTimeMillis() - start <= millis);
fail("Predicate failed after " + millis + " milliseconds");
}
}
}

0 comments on commit fb5cfa5

Please sign in to comment.