verae-fleet/test/rtt.test.js
Scott "R00tPiG Security" Lindsey (r00tpig) 1b3625ddb3 docs: zappier-edge is now verae-edge-billing
The billing edge repo and ns1 service were renamed on 2026-10-06
(marchon/verae-edge-billing, verae-edge-billing.service, /opt/verae/verae-edge-billing).
Old Forgejo URLs redirect; the old unit name and path remain as aliases/symlinks.
2026-10-06 14:00:03 -04:00

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: ['verae-edge-billing'] },
{ id: 'trees', enabled: true, capacity: 8, roles: ['tree-node'] },
];
const pick = pickMachine(machines, [], 'tree-node', 'tree-node');
assert.equal(pick.id, 'trees');
});
});