From 9fc881be2756c9859392372624385be38e4b299b Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 18:41:55 +0900 Subject: [PATCH 1/2] =?UTF-8?q?test(persistence-jpa):=20=EB=8F=99=EC=8B=9C?= =?UTF-8?q?=20writer=20=EC=8B=9C=ED=97=98=EC=9D=B4=20replay=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=EB=A5=BC=20=EB=B0=9B=EC=9D=80=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=EB=A1=9C=20=EB=B3=B8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: LiveEventLogContractTest의 「두 writer 동시 쓰기」 시험은 두 writer를 latch 하나로 동시에 푼다. 위치는 순서 없이 1·2인지 보면서, replay는 from-first, from-second 순서로 단언한다. 「먼저 제출한 writer가 1번을 받는다」고 가정하는 셈이다. 어느 writer가 allocator에 먼저 닿는지는 스케줄러가 정한다. 그래서 부하 아래에서는 second가 1번을 받고 시험이 실패한다(main 검사 run 260, d32b4b53, 434건 중 1건). 2026-09-29부터 있던 흔들림이다. 고른 방법: 각 Future가 돌려준 위치를 키로 값을 TreeMap에 모은다. 키가 정확히 1·2인지 보고, replay 순서가 위치 순서로 정렬한 값과 같은지 본다. 이 시험이 지키는 성질은 「위치가 겹치지 않고 replay가 위치 순서를 따른다」 이다. 스레드 시작 순서는 지키는 성질이 아니다. 고친 메서드의 영어 @DisplayName은 테스트 작성 규칙대로 한국어로 바꿨다. 버린 대안: - latch를 둘로 나눠 writer 순서를 강제한다. 동시에 쓰는 경우를 더는 보지 않게 되어 이 시험의 목적이 사라진다. - replay를 순서 없이(containsExactlyInAnyOrder) 본다. replay가 위치 순서를 따르는지를 놓친다. 같은 모양 찾기: 백엔드 시험 source set 전체에서 동시에 일을 푸는 파일 (CountDownLatch·CyclicBarrier·Phaser·Executors·invokeAll·supplyAsync· runAsync)과 순서 단언(containsExactly·get(0)·getFirst)이 함께 있는 파일을 grep으로 골라 읽었다. 이 시험을 빼면 27개다. 모두 앞 단계를 latch로 기다려 순서를 강제하거나, 개수·집합으로 보거나, 한 스레드가 정한 순서를 본다. 스레드 시작 순서를 결과 순서로 단언하는 곳은 이 시험 하나였다. 위험·한계: 시험 코드만 바뀐다. production 동작은 그대로다. 찾기는 위 이름 목록에 기댄다. 다른 방식으로 스레드를 만드는 시험은 보지 않았다. 검증(desktop, --no-build-cache): - RED 탐침(main + second가 먼저 위치를 잡게 강제): jpaPlatformContractTest --tests '*LiveEventLogContractTest' rc=1. 실패는 replay 단언 하나이고 실제 값은 [from-second, from-first]다. main 검사 run 260과 같은 실패다. - 고친 시험 + 같은 강제 순서: rc=0(11건 실패 0). - 고친 시험 클래스 --rerun 5회: 모두 rc=0. - :adapter:outbound:persistence-jpa:jpaPlatformContractTest 필터 없이: rc=0(434건 실패 0). - scripts/verify.sh pr --no-cache: rc=0(트리 461ffa24, 6905건 실패 0, skip 35, FROM-CACHE 0). Refs: main 검사 #148(run 260, d32b4b53) --- .../liveevent/LiveEventLogContractTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/liveevent/LiveEventLogContractTest.java b/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/liveevent/LiveEventLogContractTest.java index d847e9f4..bbe5a45b 100644 --- a/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/liveevent/LiveEventLogContractTest.java +++ b/src/adapter/outbound/persistence-jpa/src/postgresqlIntegrationTest/java/dev/caskeleton/adapter/outbound/persistence/liveevent/LiveEventLogContractTest.java @@ -17,6 +17,8 @@ import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -87,23 +89,28 @@ class LiveEventLogContractTest { } @Test - @DisplayName("two concurrent writers receive different positions and both commit") + @DisplayName("두 writer가 동시에 쓰면 서로 다른 위치 1·2를 받고, replay는 받은 위치 순서대로 둘 다 돌려준다") void concurrentWritersAllocateDistinctPositions() throws Exception { + // given CountDownLatch start = new CountDownLatch(1); + // Which writer reaches the allocator first is up to the scheduler, so the expected replay + // order is the order of the positions the writers got back, not the order they were started. + Map payloadByPosition = new TreeMap<>(); + // when try (ExecutorService executor = Executors.newFixedThreadPool(2)) { Future first = executor.submit(() -> allocateAndAppendAfter(start, "orders", "from-first")); Future second = executor.submit(() -> allocateAndAppendAfter(start, "orders", "from-second")); - start.countDown(); - - assertThat(List.of(first.get(10, TimeUnit.SECONDS), second.get(10, TimeUnit.SECONDS))) - .containsExactlyInAnyOrder(1L, 2L); + payloadByPosition.put(first.get(10, TimeUnit.SECONDS), "from-first"); + payloadByPosition.put(second.get(10, TimeUnit.SECONDS), "from-second"); } - assertThat(replayAfter("orders", 0, NOW)).containsExactly("from-first", "from-second"); + // then + assertThat(payloadByPosition).containsOnlyKeys(1L, 2L); + assertThat(replayAfter("orders", 0, NOW)).containsExactlyElementsOf(payloadByPosition.values()); } @Test From a03cca738d2060212d593aab4c01ce39b8b41820 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 21:13:57 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20#34=EA=B0=80=20=EB=82=A8=EA=B8=B4?= =?UTF-8?q?=20SpotBugs=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)); } }