Merged
fix: 清除watchdog超时定时器,防止僵尸定时器误杀后续用例 #1
haozhihangAdd on Jun 18
fix: 清除watchdog超时定时器,防止僵尸定时器误杀后续用例 #1
Merged
Merged fromhaozhihang/CPTFfix/watchdog-timeout-clearintoCPF-RN/CPTFmain
Total: 1 files changed+5-2
| @@ -939,8 +939,9 @@ export class TestRunner { | |||
| 939 | }; | 939 | }; |
| 940 | }; | 940 | }; |
| 941 | 941 | ||
| 942 | + let timeoutId: ReturnType<typeof setTimeout> | undefined; | ||
| 942 | const timeoutPromise = new Promise<TestResult>((resolve) => { | 943 | const timeoutPromise = new Promise<TestResult>((resolve) => { |
| 943 | - setTimeout(async () => { | 944 | + timeoutId = setTimeout(async () => { |
| 944 | this.logger.warn(`用例超时(${caseTimeout / 1000}s): ${testCase.id},强制终止`); | 945 | this.logger.warn(`用例超时(${caseTimeout / 1000}s): ${testCase.id},强制终止`); |
| 945 | this.appLaunched = false; | 946 | this.appLaunched = false; |
| 946 | if (this.config.bundleId) { | 947 | if (this.config.bundleId) { |
| @@ -967,7 +968,9 @@ export class TestRunner { | |||
| 967 | }, caseTimeout); | 968 | }, caseTimeout); |
| 968 | }); | 969 | }); |
| 969 | 970 | ||
| 970 | - return Promise.race([runWithWatchdog(), timeoutPromise]); | 971 | + return Promise.race([runWithWatchdog(), timeoutPromise]).finally(() => { |
| 972 | + if (timeoutId) clearTimeout(timeoutId); | ||
| 973 | + }); | ||
| 971 | } | 974 | } |
| 972 | 975 | ||
| 973 | private updateProgress(total: number, running: number, pending: number, currentTests: string[]): void { | 976 | private updateProgress(total: number, running: number, pending: number, currentTests: string[]): void { |