fix(optimizer): ускорить точный выбор проб из большого пула
This commit is contained in:
1 parent
c6dfa5267b
commit
52d8a05480
8 files changed
+306
-32
No files matched your search
@@ -35,8 +35,8 @@ test("branch bound preserves legacy assignments for ties, incompatibility and pa
|
||||
const now=Date.parse("2026-10-04T12:00:00Z");context.mock.method(Date,"now",()=>now)
|
||||
let seed=917;const random=(n:number)=>{seed=(Math.imul(seed,1664525)+1013904223)>>>0;return (seed>>>8)%n}
|
||||
const names=["","ether1","ether2"," ETHER1 "]
|
||||
for(let fixture=0;fixture<1200;fixture++){
|
||||
const count=1+random(4),wans=Array.from({length:count},()=>names[1+random(names.length-1)])
|
||||
for(let fixture=0;fixture<1230;fixture++){
|
||||
const count=fixture<1200?1+random(4):7,wans=Array.from({length:count},()=>names[1+random(names.length-1)])
|
||||
const pool=Array.from({length:count+random(3)},(_,i)=>({...probe(i,names[random(names.length)]),lastPingRttMs:random(2)?0:null,lastTxAvgMbps:random(2)?100:null,lastRxAvgMbps:random(2)?100:null,lastPingAt:random(3)?null:"2026-10-04T10:00:00Z"}))
|
||||
assert.deepEqual(chosen(wans,pool),legacy(wans,pool,now),`fixture ${fixture}`)
|
||||
}
|
||||
@@ -51,3 +51,15 @@ test("early forced choice remains unchanged when a later WAN loses its compatibl
|
||||
const wans=["ether1", "ether1"],pool=[probe(0,"ether1"),probe(1,"ether2")]
|
||||
assert.deepEqual(chosen(wans,pool),["p0",null])
|
||||
})
|
||||
|
||||
|
||||
test("DFS uses one ranking time when the clock crosses an hour boundary",context=>{
|
||||
const at=Date.parse('2026-10-07T12:00:00Z');let calls=0;context.mock.method(Date,'now',()=>at+calls++*3600000)
|
||||
const pool=Array.from({length:3},(_,i)=>({...probe(i,''),lastPingAt:new Date(at-(2-i)*3600000).toISOString()}))
|
||||
assert.deepEqual(chosen(['ether1','ether2'],pool),legacy(['ether1','ether2'],pool,at))
|
||||
})
|
||||
|
||||
test("greedy fallback remains unchanged for eight WANs and a short pool",()=>{
|
||||
const wans=Array.from({length:8},()=> 'ether1'),pool=[probe(0,'ether2'),probe(1,'ether1'),probe(2,''),probe(3,'')]
|
||||
assert.deepEqual(chosen(wans,pool),['p1','p2','p3',null,null,null,null,null])
|
||||
})
|
||||
Reference in new issue
Block a user