From a03cca738d2060212d593aab4c01ce39b8b41820 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 21:13:57 +0900 Subject: [PATCH] =?UTF-8?q?test:=20#34=EA=B0=80=20=EB=82=A8=EA=B8=B4=20Spo?= =?UTF-8?q?tBugs=20=EC=A7=80=EC=A0=81=EA=B3=BC=20=EB=B2=BD=EC=8B=9C?= =?UTF-8?q?=EA=B3=84=20=EC=83=81=ED=95=9C=20=EC=85=8B=EC=9D=84=20=EA=B3=A0?= =?UTF-8?q?=EC=B9=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit main 단계의 :adapter:inbound:graphql:spotbugsSystemTest가 #34의 `var unused = release.await(...)`를 DLS_DEAD_LOCAL_STORE로 잡아 main이 빨갛다. 이 태스크는 main 단계에만 있어 PR run에서 보이지 않았다. latch의 반환값을 쓰고, 풀려나지 않고 시한까지 간 호출 수를 센다. #34가 벽시계 시험을 고칠 때 httpclient 셋이 빠졌다. 셋 다 시한에 0.5초 여유를 둔 상한이라 부하 아래에서 원인과 상관없이 실패한다(Jetty 시험이 부하 11~15에서 1.68초 > 1.5초). #34와 같은 방식으로 고친다. - 재는 구간을 호출 하나로 좁힌다(준비 시간을 뺀다). - 상한은 시한 + 3초이고, 그 상한이 서버의 흘림·지연보다 작다는 것을 함께 단언한다(작지 않으면 상한이 아무것도 증명하지 못한다). - 늦은 헤더의 지연은 mock 서버의 종료 대기(5초)보다 짧게 둔다. Refs: RR9-03-36 --- .../runtime/RuntimeLimitsTestSupport.java | 9 +++++- .../http3/JettyAttemptDeadlineTest.java | 28 +++++++++++++++---- .../AttemptDeadlineEnforcementTest.java | 22 +++++++++++++-- .../StreamingSetupDeadlineTest.java | 18 ++++++++++-- 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/adapter/inbound/graphql/src/systemTest/java/dev/caskeleton/adapter/inbound/graphql/runtime/RuntimeLimitsTestSupport.java b/src/adapter/inbound/graphql/src/systemTest/java/dev/caskeleton/adapter/inbound/graphql/runtime/RuntimeLimitsTestSupport.java index 00b48c15..0956d4af 100644 --- a/src/adapter/inbound/graphql/src/systemTest/java/dev/caskeleton/adapter/inbound/graphql/runtime/RuntimeLimitsTestSupport.java +++ b/src/adapter/inbound/graphql/src/systemTest/java/dev/caskeleton/adapter/inbound/graphql/runtime/RuntimeLimitsTestSupport.java @@ -91,6 +91,10 @@ final class RuntimeLimitsTestSupport { static final AtomicInteger SLOW_STARTED = new AtomicInteger(); static final AtomicInteger DETAIL_INVOCATIONS = new AtomicInteger(); + + /** How many {@code slowNode} calls ran to their {@code millis} cap without being released. */ + static final AtomicInteger SLOW_CAPPED = new AtomicInteger(); + static volatile CountDownLatch slowFinished = new CountDownLatch(1); /** @@ -114,6 +118,7 @@ final class RuntimeLimitsTestSupport { static void reset() { SLOW_STARTED.set(0); DETAIL_INVOCATIONS.set(0); + SLOW_CAPPED.set(0); slowFinished = new CountDownLatch(1); slowExecutionEnded = new CountDownLatch(1); release = new CountDownLatch(1); @@ -153,7 +158,9 @@ final class RuntimeLimitsTestSupport { CountDownLatch release = SlowWork.release; try { // Released by the test, or the cap ran out; either way the resolver returns normally. - var unused = release.await(millis, TimeUnit.MILLISECONDS); + if (!release.await(millis, TimeUnit.MILLISECONDS)) { + SlowWork.SLOW_CAPPED.incrementAndGet(); + } } finally { SlowWork.slowFinished.countDown(); } diff --git a/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/http3/JettyAttemptDeadlineTest.java b/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/http3/JettyAttemptDeadlineTest.java index 1b81c012..1725fdaa 100644 --- a/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/http3/JettyAttemptDeadlineTest.java +++ b/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/http3/JettyAttemptDeadlineTest.java @@ -28,7 +28,18 @@ import org.springframework.http.client.JettyClientHttpRequestFactory; class JettyAttemptDeadlineTest { private static final Duration DEADLINE = Duration.ofSeconds(1); - private static final Duration TOLERANCE = Duration.ofMillis(500); + private static final int DRIP_BYTES = 200; + private static final Duration DRIP_GAP = Duration.ofMillis(50); + + /** How long the drip alone takes to deliver the body: 200 bytes, 50 ms apart (10 s). */ + private static final Duration DRIP_TOTAL = DRIP_GAP.multipliedBy(DRIP_BYTES); + + /** + * Time a loaded machine may add between the deadline firing and the caller seeing the failure. + * The bound only has to tell "cut at the deadline" from "waited for the drip", which the total + * leaves room for (deadline + slack is under half of it). + */ + private static final Duration SCHEDULING_SLACK = Duration.ofSeconds(3); @Test @DisplayName("Jetty 클라이언트는 바이트를 조금씩 흘리는 응답이라도 attempt deadline에 교환을 끊는다") @@ -39,13 +50,14 @@ class JettyAttemptDeadlineTest { client.start(); try (MockHttpServer server = MockHttpServer.start()) { // given - server.enqueueSlowDripBody(200, 100, Duration.ofMillis(50)); + server.enqueueSlowDripBody(200, DRIP_BYTES, DRIP_GAP); JettyClientHttpRequestFactory factory = new JettyClientHttpRequestFactory(client); - long started = System.nanoTime(); // when Throwable failure; + Duration elapsed; try (AttemptDeadline.Scope scope = AttemptDeadline.open(DEADLINE)) { + long started = System.nanoTime(); failure = catchThrowable( () -> { @@ -54,12 +66,18 @@ class JettyAttemptDeadlineTest { response.getBody().readAllBytes(); } }); + // The exchange alone: client and server setup are not part of the deadline. + elapsed = Duration.ofNanos(System.nanoTime() - started); } // then - Duration elapsed = Duration.ofNanos(System.nanoTime() - started); assertThat(failure).isInstanceOf(IOException.class); - assertThat(elapsed).isLessThan(DEADLINE.plus(TOLERANCE)); + assertThat(DEADLINE.plus(SCHEDULING_SLACK)) + .as("the bound must stay well under the drip, or it proves nothing") + .isLessThan(DRIP_TOTAL.dividedBy(2)); + assertThat(elapsed) + .as("the deadline, not the drip, ended the exchange") + .isLessThan(DEADLINE.plus(SCHEDULING_SLACK)); } finally { client.stop(); } diff --git a/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/AttemptDeadlineEnforcementTest.java b/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/AttemptDeadlineEnforcementTest.java index 02e0d264..75d83d41 100644 --- a/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/AttemptDeadlineEnforcementTest.java +++ b/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/AttemptDeadlineEnforcementTest.java @@ -28,7 +28,18 @@ import org.junit.jupiter.params.provider.EnumSource; class AttemptDeadlineEnforcementTest { private static final Duration TOTAL_CALL = Duration.ofSeconds(1); - private static final Duration TOLERANCE = Duration.ofMillis(500); + private static final int DRIP_BYTES = 200; + private static final Duration DRIP_GAP = Duration.ofMillis(50); + + /** How long the drip alone takes to deliver the body: 200 bytes, 50 ms apart (10 s). */ + private static final Duration DRIP_TOTAL = DRIP_GAP.multipliedBy(DRIP_BYTES); + + /** + * Time a loaded machine may add between the deadline firing and the caller seeing the failure. + * The bound only has to tell "cut at the deadline" from "waited for the server", which the + * server's delay leaves room for (deadline + slack is under half of it). + */ + private static final Duration SCHEDULING_SLACK = Duration.ofSeconds(3); @ParameterizedTest(name = "{0}") @EnumSource( @@ -45,7 +56,7 @@ class AttemptDeadlineEnforcementTest { .timeout(withTotalCall(TOTAL_CALL)) .build())) { // given - server.enqueueSlowDripBody(200, 100, Duration.ofMillis(50)); + server.enqueueSlowDripBody(200, DRIP_BYTES, DRIP_GAP); long started = System.nanoTime(); // when @@ -62,7 +73,12 @@ class AttemptDeadlineEnforcementTest { // then Duration elapsed = Duration.ofNanos(System.nanoTime() - started); assertThat(failure).isInstanceOf(HttpDeadlineExceededException.class); - assertThat(elapsed).isLessThan(TOTAL_CALL.plus(TOLERANCE)); + assertThat(TOTAL_CALL.plus(SCHEDULING_SLACK)) + .as("the bound must stay well under the drip, or it proves nothing") + .isLessThan(DRIP_TOTAL.dividedBy(2)); + assertThat(elapsed) + .as("the deadline, not the drip, ended the call") + .isLessThan(TOTAL_CALL.plus(SCHEDULING_SLACK)); } } diff --git a/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/StreamingSetupDeadlineTest.java b/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/StreamingSetupDeadlineTest.java index 9c85615e..5179dbf9 100644 --- a/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/StreamingSetupDeadlineTest.java +++ b/src/adapter/outbound/httpclient/src/test/java/dev/caskeleton/adapter/outbound/httpclient/restclient/StreamingSetupDeadlineTest.java @@ -37,8 +37,15 @@ import org.junit.jupiter.params.provider.EnumSource; class StreamingSetupDeadlineTest { private static final Duration TOTAL_CALL = Duration.ofSeconds(1); - private static final Duration HEADERS_DELAY = Duration.ofMillis(1800); - private static final Duration TOLERANCE = Duration.ofMillis(500); + // Under the mock server's 5 s shutdown wait: it sleeps the delay out after the client gives up. + private static final Duration HEADERS_DELAY = Duration.ofSeconds(5); + + /** + * Time a loaded machine may add between the deadline firing and the caller seeing the failure. + * The bound only has to tell "cut at the deadline" from "waited for the late headers", which the + * delay leaves room for (deadline + slack is under it). + */ + private static final Duration SCHEDULING_SLACK = Duration.ofSeconds(3); @ParameterizedTest(name = "{0}") @EnumSource( @@ -70,7 +77,12 @@ class StreamingSetupDeadlineTest { // then Duration elapsed = Duration.ofNanos(System.nanoTime() - started); assertThat(failure).isInstanceOf(HttpDeadlineExceededException.class); - assertThat(elapsed).isLessThan(TOTAL_CALL.plus(TOLERANCE)); + assertThat(TOTAL_CALL.plus(SCHEDULING_SLACK)) + .as("the bound must stay under the headers delay, or it proves nothing") + .isLessThan(HEADERS_DELAY); + assertThat(elapsed) + .as("the deadline, not the late headers, ended the setup") + .isLessThan(TOTAL_CALL.plus(SCHEDULING_SLACK)); } }