Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions test/jdk/com/sun/net/httpserver/ServerStopTerminationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final long startTime = System.nanoTime(); // taking custom start time just in case
// taking start time before entering completeExchange to account for possible
// delays in reaching server.stop().
final long startTime = System.nanoTime();

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
Expand Down Expand Up @@ -161,14 +162,15 @@ 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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but if this test fail we could envisage bumping that delay though. A better implementation could be to complete the exchange after exiting from server.stop() - without using any virtual thread, and just verifying that the server.stop() waited at least for 1s.

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(1);
log("Shutdown triggered with the delay of " + delayDuration.getSeconds());
final long elapsed = timeShutdown(delayDuration);
final long elapsed = timeShutdown(delayDuration, startTime);
log("Shutdown complete");


Expand Down Expand Up @@ -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;
}
Expand Down