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
This commit is contained in:
+8
-1
@@ -91,6 +91,10 @@ final class RuntimeLimitsTestSupport {
|
|||||||
|
|
||||||
static final AtomicInteger SLOW_STARTED = new AtomicInteger();
|
static final AtomicInteger SLOW_STARTED = new AtomicInteger();
|
||||||
static final AtomicInteger DETAIL_INVOCATIONS = 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);
|
static volatile CountDownLatch slowFinished = new CountDownLatch(1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,6 +118,7 @@ final class RuntimeLimitsTestSupport {
|
|||||||
static void reset() {
|
static void reset() {
|
||||||
SLOW_STARTED.set(0);
|
SLOW_STARTED.set(0);
|
||||||
DETAIL_INVOCATIONS.set(0);
|
DETAIL_INVOCATIONS.set(0);
|
||||||
|
SLOW_CAPPED.set(0);
|
||||||
slowFinished = new CountDownLatch(1);
|
slowFinished = new CountDownLatch(1);
|
||||||
slowExecutionEnded = new CountDownLatch(1);
|
slowExecutionEnded = new CountDownLatch(1);
|
||||||
release = new CountDownLatch(1);
|
release = new CountDownLatch(1);
|
||||||
@@ -153,7 +158,9 @@ final class RuntimeLimitsTestSupport {
|
|||||||
CountDownLatch release = SlowWork.release;
|
CountDownLatch release = SlowWork.release;
|
||||||
try {
|
try {
|
||||||
// Released by the test, or the cap ran out; either way the resolver returns normally.
|
// 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 {
|
} finally {
|
||||||
SlowWork.slowFinished.countDown();
|
SlowWork.slowFinished.countDown();
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-5
@@ -28,7 +28,18 @@ import org.springframework.http.client.JettyClientHttpRequestFactory;
|
|||||||
class JettyAttemptDeadlineTest {
|
class JettyAttemptDeadlineTest {
|
||||||
|
|
||||||
private static final Duration DEADLINE = Duration.ofSeconds(1);
|
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
|
@Test
|
||||||
@DisplayName("Jetty 클라이언트는 바이트를 조금씩 흘리는 응답이라도 attempt deadline에 교환을 끊는다")
|
@DisplayName("Jetty 클라이언트는 바이트를 조금씩 흘리는 응답이라도 attempt deadline에 교환을 끊는다")
|
||||||
@@ -39,13 +50,14 @@ class JettyAttemptDeadlineTest {
|
|||||||
client.start();
|
client.start();
|
||||||
try (MockHttpServer server = MockHttpServer.start()) {
|
try (MockHttpServer server = MockHttpServer.start()) {
|
||||||
// given
|
// given
|
||||||
server.enqueueSlowDripBody(200, 100, Duration.ofMillis(50));
|
server.enqueueSlowDripBody(200, DRIP_BYTES, DRIP_GAP);
|
||||||
JettyClientHttpRequestFactory factory = new JettyClientHttpRequestFactory(client);
|
JettyClientHttpRequestFactory factory = new JettyClientHttpRequestFactory(client);
|
||||||
long started = System.nanoTime();
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Throwable failure;
|
Throwable failure;
|
||||||
|
Duration elapsed;
|
||||||
try (AttemptDeadline.Scope scope = AttemptDeadline.open(DEADLINE)) {
|
try (AttemptDeadline.Scope scope = AttemptDeadline.open(DEADLINE)) {
|
||||||
|
long started = System.nanoTime();
|
||||||
failure =
|
failure =
|
||||||
catchThrowable(
|
catchThrowable(
|
||||||
() -> {
|
() -> {
|
||||||
@@ -54,12 +66,18 @@ class JettyAttemptDeadlineTest {
|
|||||||
response.getBody().readAllBytes();
|
response.getBody().readAllBytes();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// The exchange alone: client and server setup are not part of the deadline.
|
||||||
|
elapsed = Duration.ofNanos(System.nanoTime() - started);
|
||||||
}
|
}
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Duration elapsed = Duration.ofNanos(System.nanoTime() - started);
|
|
||||||
assertThat(failure).isInstanceOf(IOException.class);
|
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 {
|
} finally {
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-3
@@ -28,7 +28,18 @@ import org.junit.jupiter.params.provider.EnumSource;
|
|||||||
class AttemptDeadlineEnforcementTest {
|
class AttemptDeadlineEnforcementTest {
|
||||||
|
|
||||||
private static final Duration TOTAL_CALL = Duration.ofSeconds(1);
|
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}")
|
@ParameterizedTest(name = "{0}")
|
||||||
@EnumSource(
|
@EnumSource(
|
||||||
@@ -45,7 +56,7 @@ class AttemptDeadlineEnforcementTest {
|
|||||||
.timeout(withTotalCall(TOTAL_CALL))
|
.timeout(withTotalCall(TOTAL_CALL))
|
||||||
.build())) {
|
.build())) {
|
||||||
// given
|
// given
|
||||||
server.enqueueSlowDripBody(200, 100, Duration.ofMillis(50));
|
server.enqueueSlowDripBody(200, DRIP_BYTES, DRIP_GAP);
|
||||||
long started = System.nanoTime();
|
long started = System.nanoTime();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -62,7 +73,12 @@ class AttemptDeadlineEnforcementTest {
|
|||||||
// then
|
// then
|
||||||
Duration elapsed = Duration.ofNanos(System.nanoTime() - started);
|
Duration elapsed = Duration.ofNanos(System.nanoTime() - started);
|
||||||
assertThat(failure).isInstanceOf(HttpDeadlineExceededException.class);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-3
@@ -37,8 +37,15 @@ import org.junit.jupiter.params.provider.EnumSource;
|
|||||||
class StreamingSetupDeadlineTest {
|
class StreamingSetupDeadlineTest {
|
||||||
|
|
||||||
private static final Duration TOTAL_CALL = Duration.ofSeconds(1);
|
private static final Duration TOTAL_CALL = Duration.ofSeconds(1);
|
||||||
private static final Duration HEADERS_DELAY = Duration.ofMillis(1800);
|
// Under the mock server's 5 s shutdown wait: it sleeps the delay out after the client gives up.
|
||||||
private static final Duration TOLERANCE = Duration.ofMillis(500);
|
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}")
|
@ParameterizedTest(name = "{0}")
|
||||||
@EnumSource(
|
@EnumSource(
|
||||||
@@ -70,7 +77,12 @@ class StreamingSetupDeadlineTest {
|
|||||||
// then
|
// then
|
||||||
Duration elapsed = Duration.ofNanos(System.nanoTime() - started);
|
Duration elapsed = Duration.ofNanos(System.nanoTime() - started);
|
||||||
assertThat(failure).isInstanceOf(HttpDeadlineExceededException.class);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user