feat(retry): B24 冷却扩围到「不回包/解密失败成片」两形

连接层冷却只认「会话没建立」,而现网 B26 的成片失败是连接已建立的两种形状:
对端在给出响应前收连接、HTTP 200 里行级结论带解密失败。给冷却表加第二条
证据道(同 host 分格、同窗长、同阈值 2),品牌客户端把两形都记进这条道:
不回包按异常即时记证;解密形状先批内开票,批终态只在零可结算结论时按票
记证——一枚干净结论就整票作废,脏品牌名的行级差异证据面保持不变。
冷却期快失败沿用既有整批分支,归因文案单独一条以便交付侧与取证区分。
This commit is contained in:
2026-10-26 14:01:26 +08:00
parent 1d4b4decf3
commit a3f765c458
4 changed files with 390 additions and 9 deletions
@@ -74,4 +74,82 @@ class UnreachableCooldownTest {
assertThat(UnreachableCooldown.isConnectFailure(new RuntimeException("read timeout"))).isFalse();
assertThat(UnreachableCooldown.isConnectFailure(null)).isFalse();
}
// ---- no-answer 道(B24 扩围,2026-10-26 拍板):阈值/窗长/到期语义与 connect 道同款 ----
@Test
void twoNoAnswerFailuresEnterCooldownOneDoesNot() {
String host = "http://16890.example";
assertThat(cooldown.recordNoAnswerFailure(host, WINDOW)).isFalse();
assertThat(cooldown.isCoolingDown(host, WINDOW)).isFalse();
assertThat(cooldown.recordNoAnswerFailure(host, WINDOW)).isTrue();
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isTrue();
assertThat(cooldown.isCoolingDown(host, WINDOW)).isTrue();
}
@Test
void noAnswerWindowExpiresAndSingleFailureReenters() throws InterruptedException {
String host = "http://expire-16890.example";
cooldown.recordNoAnswerFailure(host, 50);
cooldown.recordNoAnswerFailure(host, 50);
assertThat(cooldown.noAnswerLaneCooling(host, 50)).isTrue();
Thread.sleep(120);
assertThat(cooldown.noAnswerLaneCooling(host, 50)).isFalse();
// 历史证据不清零:到期后批次再判成片,一次即重进(与 connect 道同拍板口径)
assertThat(cooldown.recordNoAnswerFailure(host, 50)).isTrue();
assertThat(cooldown.noAnswerLaneCooling(host, 50)).isTrue();
}
@Test
void clearNoAnswerEvidenceRequiresTwoFreshFailures() {
String host = "http://clear.example";
cooldown.recordNoAnswerFailure(host, WINDOW);
cooldown.clearNoAnswerEvidence(host);
assertThat(cooldown.recordNoAnswerFailure(host, WINDOW)).isFalse();
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isFalse();
}
@Test
void clearOnlyTouchesNoAnswerEvidenceAndNeverAnOpenedWindow() {
String host = "http://window-stays.example";
cooldown.recordNoAnswerFailure(host, WINDOW);
cooldown.recordNoAnswerFailure(host, WINDOW);
// 已开的窗不因清零提前放行:快失败只按窗长自然到期(connect 道同语义)
cooldown.clearNoAnswerEvidence(host);
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isTrue();
// 到期后靠那一次成片失败重进:清零历史后证据要重新攒满两条,这里只缺一条
cooldown.clearNoAnswerEvidence(host);
assertThat(cooldown.recordNoAnswerFailure(host, WINDOW)).isFalse();
}
@Test
void zeroWindowDisablesNoAnswerLaneToo() {
for (int i = 0; i < 5; i++) {
assertThat(cooldown.recordNoAnswerFailure("http://off.example", 0)).isFalse();
}
assertThat(cooldown.noAnswerLaneCooling("http://off.example", 0)).isFalse();
}
@Test
void connectLaneAndNoAnswerLaneAreSeparateAccounts() {
String host = "http://lanes.example";
cooldown.recordConnectFailure(host, WINDOW);
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isFalse();
cooldown.recordNoAnswerFailure(host, WINDOW);
// 两条道各计各的:一条 connect + 一条 no-answer 都不到阈值
assertThat(cooldown.connectLaneCooling(host, WINDOW)).isFalse();
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isFalse();
cooldown.recordConnectFailure(host, WINDOW);
assertThat(cooldown.connectLaneCooling(host, WINDOW)).isTrue();
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isFalse();
// recordConnected 只清 connect 证据;no-answer 证据必须活过它
cooldown.recordConnected(host);
assertThat(cooldown.recordNoAnswerFailure(host, WINDOW)).isTrue();
assertThat(cooldown.noAnswerLaneCooling(host, WINDOW)).isTrue();
assertThat(cooldown.connectLaneCooling(host, WINDOW)).isTrue();
}
}