42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
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');
|
|
});
|
|
});
|