test: #34가 남긴 SpotBugs 지적과 벽시계 상한 셋을 고친다 #43
+8
-1
@@ -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();
|
||||
}
|
||||
|
||||
+23
-5
@@ -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();
|
||||
}
|
||||
|
||||
+19
-3
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-3
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user