🐛 fix: 合并上传收尾有限重试修复

* 避免处理中响应重置失败计数导致无限轮询
* 保留网络故障后的手动完成能力并验证错误交替场景
This commit is contained in:
orion committed 2026-10-06 02:06:32 +08:00
commit b67d36d8a0
2 files changed
+13 -1

No files matched your search

-1
View File
@@ -11,7 +11,6 @@ export async function waitForUploadCompletion<T>(request: () => Promise<ApiRespo
signal?.throwIfAborted() signal?.throwIfAborted()
try { try {
const response = await request() const response = await request()
failures = 0
if (response.code !== 202) return response if (response.code !== 202) return response
if (!announced) { announced = true; onFinalizing?.() } if (!announced) { announced = true; onFinalizing?.() }
} catch (error) { } catch (error) {
+13
View File
@@ -19,3 +19,16 @@ test('transient network failure during verification retries the same completion
calls++;if(calls===1)return {code:202};if(calls===2)throw new Error('offline');return {code:200,detail:{code:'SAMECODE'}} calls++;if(calls===1)return {code:202};if(calls===2)throw new Error('offline');return {code:200,detail:{code:'SAMECODE'}}
});assert.equal(calls,3);assert.equal(result.detail.code,'SAMECODE') });assert.equal(calls,3);assert.equal(result.detail.code,'SAMECODE')
}) })
test('pending replies between failed completion tasks do not reset the retry limit',async t=>{
t.mock.timers.enable({apis:['setTimeout']})
let calls=0
const pending=waitForUploadCompletion(async()=>{
calls++;if(calls%2===1)return {code:202}
throw Object.assign(new Error('storage unavailable'),{response:{status:503}})
})
const rejected=assert.rejects(pending,/storage unavailable/)
for(let i=0;i<8;i++){await new Promise(r=>setImmediate(r));t.mock.timers.tick(3000)}
await rejected;assert.equal(calls,8);t.mock.timers.reset()
})