From ef1208e7c9a3a0e01bcd4daffe4373e7cf700596 Mon Sep 17 00:00:00 2001 From: JasonShane Date: Thu, 5 Nov 2026 18:40:53 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=20hash-pool=20?= =?UTF-8?q?=E6=8A=A2=E5=8D=A0=E6=B5=8B=E8=AF=95=E7=9A=84=E6=97=B6=E5=BA=8F?= =?UTF-8?q?=E7=AB=9E=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 被抢占任务 bg-a 原为 4 字节极小文件,CI 低负载下 worker 可能在 abort 消息派发前就完成哈希,导致 promise 正常 resolve 而非抛出 PreemptedError(Node 22 CI 已两次复现)。改为 64MB 与同文件并行性测试保持一致,确保抢占必然在块边界生效。 --- tests/hash-pool.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/hash-pool.test.js b/tests/hash-pool.test.js index 71c6590..1293ccc 100644 --- a/tests/hash-pool.test.js +++ b/tests/hash-pool.test.js @@ -121,12 +121,15 @@ it('OPT-3:并发 2 时第二任务在前一任务完成前启动(并行执 it('OPT-3:并发 2 下前台任务只抢占一个后台槽位,另一后台任务继续完成', async () => { setHashPoolConcurrency(2) try { - const a = await writeFixture('pr-a.bin', Buffer.from('bg-a')) + const a = await writeFixture('pr-a.bin', Buffer.alloc(64 * 1024 * 1024, 1)) const b = await writeFixture('pr-b.bin', Buffer.from('bg-b')) const c = await writeFixture('pr-c.bin', Buffer.from('priority')) // 同一 tick 内入队:a/b 占满两个槽位(currentTask 同步置位), - // 随后到达的前台任务 c 无空闲槽位 → 抢占其一(a),b 不受影响 + // 随后到达的前台任务 c 无空闲槽位 → 抢占其一(a),b 不受影响。 + // a 必须足够大(SHA256 耗时远大于 worker 消息往返):抢占依赖 worker + // 在块边界收到 abort 消息,若 a 过小则可能在 abort 派发前就完成, + // 导致 promise 正常 resolve 而非 PreemptedError(CI 低负载下已复现) const pa = computeFileHashOffThread(a.abs) const pb = computeFileHashOffThread(b.abs) const pc = computeFileHashOffThread(c.abs, undefined, undefined, {