Initial import of verae-fleet from zapier monorepo
This commit is contained in:
commit
0a7edcf999
36 changed files with 2400 additions and 0 deletions
42
test/rtt.test.js
Normal file
42
test/rtt.test.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { summarizeRtt, RttWindow } from '../src/rtt.js';
|
||||
import { pickMachine } from '../src/machines.js';
|
||||
|
||||
describe('RTT planning stats', () => {
|
||||
it('computes min, avg, p50, p90 in order', () => {
|
||||
const s = summarizeRtt([10, 20, 30, 40, 50, 60, 70, 80, 90, 100]);
|
||||
assert.equal(s.count, 10);
|
||||
assert.equal(s.minMs, 10);
|
||||
assert.equal(s.avgMs, 55);
|
||||
assert.ok(s.p50Ms >= s.minMs && s.p50Ms <= s.p90Ms);
|
||||
assert.ok(s.p90Ms <= 100);
|
||||
});
|
||||
|
||||
it('empty window is nulls', () => {
|
||||
const s = new RttWindow().stats();
|
||||
assert.equal(s.count, 0);
|
||||
assert.equal(s.minMs, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('machine placement', () => {
|
||||
it('spreads onto the least-loaded eligible host', () => {
|
||||
const machines = [
|
||||
{ id: 'a', enabled: true, capacity: 4, roles: ['*'] },
|
||||
{ id: 'b', enabled: true, capacity: 4, roles: ['*'] },
|
||||
];
|
||||
const instances = [{ machine: 'a', pid: 1 }];
|
||||
const pick = pickMachine(machines, instances, 'tree-node', 'tree-node');
|
||||
assert.equal(pick.id, 'b');
|
||||
});
|
||||
|
||||
it('skips machines that do not allow the role', () => {
|
||||
const machines = [
|
||||
{ id: 'edge', enabled: true, capacity: 8, roles: ['zappier-edge'] },
|
||||
{ id: 'trees', enabled: true, capacity: 8, roles: ['tree-node'] },
|
||||
];
|
||||
const pick = pickMachine(machines, [], 'tree-node', 'tree-node');
|
||||
assert.equal(pick.id, 'trees');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue