diff --git a/src/adapter/inbound/web/src/jettyCompatTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/JettyLoadAndShutdownIT.java b/src/adapter/inbound/web/src/jettyCompatTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/JettyLoadAndShutdownIT.java
index 5e310429..f3bc7541 100644
--- a/src/adapter/inbound/web/src/jettyCompatTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/JettyLoadAndShutdownIT.java
+++ b/src/adapter/inbound/web/src/jettyCompatTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/JettyLoadAndShutdownIT.java
@@ -1,9 +1,6 @@
package dev.caskeleton.adapter.inbound.web.testkit.performance;
-import static org.assertj.core.api.Assertions.assertThat;
-
import dev.caskeleton.webtestkit.ContractFixtureApplication;
-import java.time.Duration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -11,10 +8,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
/**
- * Load, abuse and graceful shutdown on the the second servlet container.
+ * Load, abuse and graceful shutdown on the second servlet container.
*
*
Shutdown is asserted per container rather than once, because it is implemented per container.
* "Stop accepting, finish what is in flight" is a promise each server keeps in its own way, and the
@@ -22,7 +20,7 @@ import org.springframework.test.context.ActiveProfiles;
* like the network.
*/
@SpringBootTest(
- classes = ContractFixtureApplication.class,
+ classes = {ContractFixtureApplication.class, InFlightFixtureController.class},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = "server.shutdown=graceful")
@ActiveProfiles("web-contract")
@@ -32,6 +30,8 @@ class JettyLoadAndShutdownIT extends WebLoadAndShutdownContract {
@Autowired private ServletWebServerApplicationContext context;
+ @Autowired private InFlightFixtureController inFlight;
+
@Override
protected WebLoadFixture fixture() {
return new WebLoadFixture(port);
@@ -44,20 +44,10 @@ class JettyLoadAndShutdownIT extends WebLoadAndShutdownContract {
@Test
@Tag("web-shutdown")
- @DisplayName("graceful shutdown drains within the deployment's grace period")
- void gracefulShutdownFinishesInFlightWork() {
- // Last, and destructive: the context serves nothing afterwards.
- WebLoadFixture fixture = fixture();
- assertThat(fixture.stillServing(loadPath())).isTrue();
-
- GracefulShutdownProbe.Outcome outcome =
- GracefulShutdownProbe.shutDown(webServer(), Duration.ofSeconds(10));
-
- // Bounded on purpose. A shutdown that waits indefinitely for a connection to go idle is how a
- // rolling deploy stalls with half the fleet drained — and it produces no error to alert on.
- assertThat(outcome.took()).isLessThan(Duration.ofSeconds(15));
- assertThat(fixture.stillServing(loadPath()))
- .as("the server accepted a new request after it was told to stop")
- .isFalse();
+ @DisplayName("graceful 종료는 처리 중인 요청을 끝까지 답한 뒤 유예 시간 안에 IDLE로 끝난다")
+ // Destructive: the server is stopped, so the context is thrown away for whatever runs next.
+ @DirtiesContext
+ void gracefulShutdownFinishesInFlightWork() throws InterruptedException {
+ assertShutdownFinishesInFlightWork(inFlight);
}
}
diff --git a/src/adapter/inbound/web/src/performanceTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/TomcatLoadAndShutdownIT.java b/src/adapter/inbound/web/src/performanceTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/TomcatLoadAndShutdownIT.java
index e1fef5b5..1d13d42a 100644
--- a/src/adapter/inbound/web/src/performanceTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/TomcatLoadAndShutdownIT.java
+++ b/src/adapter/inbound/web/src/performanceTest/java/dev/caskeleton/adapter/inbound/web/testkit/performance/TomcatLoadAndShutdownIT.java
@@ -1,9 +1,6 @@
package dev.caskeleton.adapter.inbound.web.testkit.performance;
-import static org.assertj.core.api.Assertions.assertThat;
-
import dev.caskeleton.webtestkit.ContractFixtureApplication;
-import java.time.Duration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -11,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContext;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
/**
@@ -22,7 +20,7 @@ import org.springframework.test.context.ActiveProfiles;
* like the network.
*/
@SpringBootTest(
- classes = ContractFixtureApplication.class,
+ classes = {ContractFixtureApplication.class, InFlightFixtureController.class},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = "server.shutdown=graceful")
@ActiveProfiles("web-contract")
@@ -32,6 +30,8 @@ class TomcatLoadAndShutdownIT extends WebLoadAndShutdownContract {
@Autowired private ServletWebServerApplicationContext context;
+ @Autowired private InFlightFixtureController inFlight;
+
@Override
protected WebLoadFixture fixture() {
return new WebLoadFixture(port);
@@ -44,20 +44,10 @@ class TomcatLoadAndShutdownIT extends WebLoadAndShutdownContract {
@Test
@Tag("web-shutdown")
- @DisplayName("graceful shutdown drains within the deployment's grace period")
- void gracefulShutdownFinishesInFlightWork() {
- // Last, and destructive: the context serves nothing afterwards.
- WebLoadFixture fixture = fixture();
- assertThat(fixture.stillServing(loadPath())).isTrue();
-
- GracefulShutdownProbe.Outcome outcome =
- GracefulShutdownProbe.shutDown(webServer(), Duration.ofSeconds(10));
-
- // Bounded on purpose. A shutdown that waits indefinitely for a connection to go idle is how a
- // rolling deploy stalls with half the fleet drained — and it produces no error to alert on.
- assertThat(outcome.took()).isLessThan(Duration.ofSeconds(15));
- assertThat(fixture.stillServing(loadPath()))
- .as("the server accepted a new request after it was told to stop")
- .isFalse();
+ @DisplayName("graceful 종료는 처리 중인 요청을 끝까지 답한 뒤 유예 시간 안에 IDLE로 끝난다")
+ // Destructive: the server is stopped, so the context is thrown away for whatever runs next.
+ @DirtiesContext
+ void gracefulShutdownFinishesInFlightWork() throws InterruptedException {
+ assertShutdownFinishesInFlightWork(inFlight);
}
}
diff --git a/src/adapter/inbound/web/src/testFixtures/java/dev/caskeleton/adapter/inbound/web/testkit/performance/GracefulShutdownProbe.java b/src/adapter/inbound/web/src/testFixtures/java/dev/caskeleton/adapter/inbound/web/testkit/performance/GracefulShutdownProbe.java
index b5d327d9..47a40390 100644
--- a/src/adapter/inbound/web/src/testFixtures/java/dev/caskeleton/adapter/inbound/web/testkit/performance/GracefulShutdownProbe.java
+++ b/src/adapter/inbound/web/src/testFixtures/java/dev/caskeleton/adapter/inbound/web/testkit/performance/GracefulShutdownProbe.java
@@ -4,19 +4,21 @@ import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+import org.springframework.boot.web.server.GracefulShutdownResult;
import org.springframework.boot.web.server.WebServer;
/**
* Drives a graceful shutdown and refuses to wait for ever.
*
- *
Bounded because unbounded is the actual failure mode. {@code shutDownGracefully} waits for
- * in-flight work, and on Reactor Netty a connection that is open but idle counts — so calling it
- * with a lingering keep-alive connection never returns. In a test that manifests as a hung build
- * with no output; in a deployment it manifests as a rolling restart that stalls with half the fleet
- * drained and no error anywhere.
+ *
Bounded because unbounded is the actual failure mode. Tomcat and Jetty report a graceful
+ * shutdown only once their active requests finish, and set no limit of their own: the limit is
+ * Spring's per-phase lifecycle timeout, which calling the server directly bypasses. So one request
+ * that never finishes means the server never reports, and in a test that manifests as a hung build
+ * with no output.
*
- *
The probe therefore measures rather than assumes, and reports "did not finish within the grace
- * period" as a result the caller can assert on.
+ *
The probe therefore measures rather than assumes, and reports what the server said — or that
+ * it said nothing within the grace period — as a result the caller can assert on.
*/
public final class GracefulShutdownProbe {
@@ -25,20 +27,53 @@ public final class GracefulShutdownProbe {
/**
* What a shutdown attempt did.
*
- * @param finishedGracefully whether the server reported completion within the grace period
- * @param took how long it took, capped at the grace period
+ * @param result what the server reported when it finished, or {@code null} if it reported nothing
+ * within the grace period
+ * @param took how long it took, capped at the grace period plus the draining step
*/
- public record Outcome(boolean finishedGracefully, Duration took) {}
+ public record Outcome(GracefulShutdownResult result, Duration took) {
+
+ /**
+ * Whether the server waited for its requests and then reported itself idle within the grace
+ * period.
+ *
+ *
{@link GracefulShutdownResult#IMMEDIATE} is not graceful: it is what a server without
+ * graceful shutdown reports at once, while its requests are still running. Counting it as a
+ * finish is how a check passes with {@code server.shutdown=immediate}.
+ */
+ public boolean finishedGracefully() {
+ return result == GracefulShutdownResult.IDLE;
+ }
+ }
+
+ /** What the draining step can ask about the shutdown it runs inside. */
+ @FunctionalInterface
+ public interface Draining {
+
+ /**
+ * Waits up to {@code window} for the server to report its shutdown finished, and says whether
+ * it did. Asked while a request is still held, {@code true} means the server did not wait for
+ * it: a graceful server cannot finish while one of its requests is still running, so a correct
+ * server never makes this {@code true} however slow the machine.
+ *
+ * @param window how long to give a server that reports without waiting, possibly from another
+ * thread and a little late
+ */
+ boolean reportedWithin(Duration window);
+ }
/**
- * Asks a server to stop and waits at most {@code grace}.
+ * Asks a server to stop, runs {@code whileDraining}, then waits at most {@code grace}.
*
* @param server the server to stop
* @param grace the longest a rolling deploy is willing to wait for one instance
+ * @param whileDraining what the caller observes and finishes after shutdown began and before the
+ * server is stopped — a request still in flight is released here
*/
- public static Outcome shutDown(WebServer server, Duration grace) {
+ public static Outcome shutDown(
+ WebServer server, Duration grace, Consumer whileDraining) {
CountDownLatch finished = new CountDownLatch(1);
- AtomicReference