Merge branch 'main' into claude/r9-b-outbound
pr / done (pull_request) Successful in 13m14s

This commit is contained in:
2026-11-13 17:13:54 +00:00
5 changed files with 78 additions and 18 deletions
@@ -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();
}
@@ -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();
}
@@ -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));
}
}
@@ -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));
}
}
@@ -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<Long, String> payloadByPosition = new TreeMap<>();
// when
try (ExecutorService executor = Executors.newFixedThreadPool(2)) {
Future<Long> first =
executor.submit(() -> allocateAndAppendAfter(start, "orders", "from-first"));
Future<Long> 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