fix(任务判死): 外观/货源判死文案按证据陈述,不再断言 Python 中断
2026-10-01 三条外观任务被心跳判死时一行业务结果都没回传过(Linux worker 一次领 5 条却只有 2 个采集槽,多出来的任务零心跳零分片直到钟面走完),而文案固定写 "Python interrupted before uploading final result",把「没开跑」说成「跑挂了」,排查方向被带偏过一次。现在按已落库分片数、 最后回传/心跳时间、客户端最后一次上报的位置分述;结果文件作业重试耗尽也不再写成客户端中断。
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
package com.nanri.aiimage.common.util;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class StaleTaskDeathReasonTest {
|
||||
|
||||
private static final LocalDateTime T = LocalDateTime.of(2026, 10, 1, 12, 34, 5);
|
||||
|
||||
@Test
|
||||
void neverUploadedSaysNoResultUploadedNotThatPythonCrashed() {
|
||||
String reason = new StaleTaskDeathReason(0L, null, T, null, false, 30).describe();
|
||||
assertTrue(reason.contains("未回传任何检测结果"), reason);
|
||||
assertTrue(reason.contains("超过 30 分钟无进展"), reason);
|
||||
assertTrue(reason.contains("最后心跳 10-01 12:34"), reason);
|
||||
assertFalse(reason.contains("Python"), reason);
|
||||
assertFalse(reason.contains("最后上报"), reason);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queuedTaskIsToldApartFromACrashedOneByTheReportedPhase() {
|
||||
String reason = new StaleTaskDeathReason(0L, null, T, "排队等待空闲槽位", false, 30).describe();
|
||||
assertTrue(reason.contains("最后上报 排队等待空闲槽位"), reason);
|
||||
assertFalse(reason.contains("已收到"), reason);
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingHeartbeatAndBlankPhaseDegradeQuietly() {
|
||||
String reason = new StaleTaskDeathReason(0L, null, null, " ", false, 30).describe();
|
||||
assertTrue(reason.contains("最后心跳 时间未知"), reason);
|
||||
assertFalse(reason.contains("最后上报"), reason);
|
||||
}
|
||||
|
||||
@Test
|
||||
void interruptedUploadReportsChunksAndLastChunkTime() {
|
||||
String reason = new StaleTaskDeathReason(7L, T, T, "第 120/500 组", false, 30).describe();
|
||||
assertTrue(reason.contains("客户端回传中断"), reason);
|
||||
assertTrue(reason.contains("已收到 7 个分片,最后一次 10-01 12:34"), reason);
|
||||
assertTrue(reason.contains("最后上报 第 120/500 组"), reason);
|
||||
assertFalse(reason.contains("结果文件生成"), reason);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exhaustedFileJobBlamesFileGenerationInsteadOfTheClient() {
|
||||
String reason = new StaleTaskDeathReason(7L, T, T, "第 120/500 组", true, 30).describe();
|
||||
assertTrue(reason.contains("结果文件生成多次失败"), reason);
|
||||
assertFalse(reason.contains("回传中断"), reason);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exhaustedFileJobWithoutAnyChunkStillReportsClientSilence() {
|
||||
String reason = new StaleTaskDeathReason(0L, null, T, null, true, 30).describe();
|
||||
assertTrue(reason.contains("未回传任何检测结果"), reason);
|
||||
assertFalse(reason.contains("结果文件生成"), reason);
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonPositiveTimeoutNeverPrintsZeroMinutes() {
|
||||
assertTrue(new StaleTaskDeathReason(0L, null, null, null, false, 0)
|
||||
.describe().contains("超过 1 分钟"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user