diff --git a/test/jdk/com/sun/net/httpserver/ServerStopTerminationTest.java b/test/jdk/com/sun/net/httpserver/ServerStopTerminationTest.java index 8156116072585..408290ca8a15a 100644 --- a/test/jdk/com/sun/net/httpserver/ServerStopTerminationTest.java +++ b/test/jdk/com/sun/net/httpserver/ServerStopTerminationTest.java @@ -124,13 +124,14 @@ public void shouldAwaitActiveExchange() throws InterruptedException { // Complete the exchange one second into the future final Duration exchangeDuration = Duration.ofSeconds(1); + final long startTime = System.nanoTime(); // taking custom start time just in case completeExchange(exchangeDuration); log("Complete Exchange triggered"); // Time the shutdown sequence - final Duration delayDuration = Duration.ofSeconds(Utils.adjustTimeout(5)); + final Duration delayDuration = Duration.ofSeconds(Utils.adjustTimeout(20)); log("Shutdown triggered with the delay of " + delayDuration.getSeconds()); - final long elapsed = timeShutdown(delayDuration); + final long elapsed = timeShutdown(delayDuration, startTime); log("Shutdown complete"); // The shutdown should take at least as long as the exchange duration @@ -161,6 +162,7 @@ public void shouldCompeteAfterDelay() throws InterruptedException { // Complete the exchange 10 second into the future. // Runs in parallel, so won't block the server stop final Duration exchangeDuration = Duration.ofSeconds(Utils.adjustTimeout(10)); + final long startTime = System.nanoTime(); // taking custom start time just in case completeExchange(exchangeDuration); log("Complete Exchange triggered"); @@ -168,7 +170,7 @@ public void shouldCompeteAfterDelay() throws InterruptedException { // Time the shutdown sequence final Duration delayDuration = Duration.ofSeconds(1); log("Shutdown triggered with the delay of " + delayDuration.getSeconds()); - final long elapsed = timeShutdown(delayDuration); + final long elapsed = timeShutdown(delayDuration, startTime); log("Shutdown complete"); @@ -277,7 +279,14 @@ public void shouldAllowRepeatedStop() { */ private long timeShutdown(Duration delayDuration) { final long startTime = System.nanoTime(); + return timeShutdown(delayDuration, startTime); + } + /** + * This allows passing a custom start time + */ + private long timeShutdown(Duration delayDuration, + long startTime) { server.stop((int) delayDuration.toSeconds()); return System.nanoTime() - startTime; }