Files
Endoleap/tests/headless/import-batches.test.mjs
T

18 lines
1.6 KiB
JavaScript

/**
* 导入发布批量的自适应控制测试。目标耗时保持不变,根据固定发布成本与每项成本增减批量,而不是固定每批若干项。
*/
import {test} from 'node:test';
import assert from 'node:assert/strict';
import {createImportBatches} from '../../src/lib/canvas-runtime/import-batches.ts';
// 从单项起步,在固定成本占主导且每项便宜时逐渐增至 32 上限;目标耗时仍为 6,不通过抬高预算换吞吐。
test('fixed publication cost can grow beyond singleton batches without raising the time budget',()=>{
// record 接收合成耗时而非测量真实发布;4 是固定成本,.05 是每项成本,只验证反馈算法的增长轨迹。
const batches=createImportBatches(6,32);assert.equal(batches.observed,false);assert.equal(batches.limit,1);const sizes=[];
for(let i=0;i<20;i++){const n=batches.limit;sizes.push(n);batches.record(n,4+n*.05);}
assert.equal(batches.observed,true);assert.equal(batches.limit,32);assert.ok(sizes.includes(2));assert.ok(sizes.every(n=>n<=32));
});
// 不足一整批的尾项不用于虚增容量;昂贵整批迅速退回一项,后续单项成本降低后再渐进恢复。
test('expensive batches back off, then recover as costs fall; partial tails do not inflate the limit',()=>{
const batches=createImportBatches(6,32);for(let i=0;i<4;i++)batches.record(batches.limit,1);const full=batches.limit;batches.record(1,1);assert.equal(batches.limit,full);batches.record(full,60);assert.equal(batches.limit,1);batches.record(1,12);assert.equal(batches.limit,1);batches.record(1,2);assert.equal(batches.limit,2);batches.record(2,2);assert.equal(batches.limit,3);
});