fix(回归): 超时用例的尺子改成"在配置超时附近失败",不再绑死 JDK 异常子类
全量回归负载下这支用例连红两轮,根因是 IOException: connection closed locally (超时掐断的第三种 JDK 表现,历史 e68... 已为前两种放宽过一次)。补上耗时下界后 "读超时被钳成即时"这类真缺陷反而会判红,所以这是收紧不是放水。
This commit is contained in:
+19
-3
@@ -124,11 +124,14 @@ class HttpClientTimeoutEffectiveTest {
|
||||
@Test
|
||||
void timeoutRootIsTimeoutException() {
|
||||
RestClient client = clientWithReadTimeout(200);
|
||||
long startedAt = System.nanoTime();
|
||||
ResourceAccessException ex = assertThrows(ResourceAccessException.class,
|
||||
() -> client.get().uri(baseUrl() + "/slow?ms=2000").retrieve().toBodilessEntity());
|
||||
// JDK 在负载下可能抛 java.util.concurrent.TimeoutException 或 java.net.http.HttpTimeoutException,
|
||||
// 两者同属"超时";按超时语义断言而非绑定具体类型。
|
||||
assertTrue(isTimeoutRoot(ex), "根因应为超时异常,实际 " + root(ex));
|
||||
long elapsedMs = (System.nanoTime() - startedAt) / 1_000_000;
|
||||
// 尺子是"在配置的 200ms 附近失败":早于配置值 = 超时被钳成即时,晚于端点的 2000ms = 根本没超时。
|
||||
assertTrue(elapsedMs >= 150L, "不应早于配置的读超时失败:" + elapsedMs + "ms");
|
||||
assertTrue(elapsedMs < 2_500L, "慢端点应在配置超时附近失败,实际 " + elapsedMs + "ms");
|
||||
assertTrue(isTimeoutFamilyRoot(ex), "根因应为超时或超时中止,实际 " + root(ex));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,4 +213,17 @@ class HttpClientTimeoutEffectiveTest {
|
||||
return root(error) instanceof TimeoutException
|
||||
|| root(error) instanceof java.net.http.HttpTimeoutException;
|
||||
}
|
||||
|
||||
/**
|
||||
* 超时中止在 JDK 里有两类可见根因:超时类,以及请求被本地掐断后的
|
||||
* {@code IOException: connection closed locally}(全量回归负载下实测到的第三种形态)。
|
||||
* 只多认这一条消息,其余异常照旧判红。
|
||||
*/
|
||||
private static boolean isTimeoutFamilyRoot(Throwable error) {
|
||||
Throwable r = root(error);
|
||||
if (isTimeoutRoot(r) || isTimeoutRoot(error)) {
|
||||
return true;
|
||||
}
|
||||
return r instanceof IOException && String.valueOf(r.getMessage()).contains("connection closed locally");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user