About: how pages are checked

tests/sims/mesh.test.ts

The automated tests for the /simulators/service-mesh simulator. They run the model on its own, outside the browser, and compare it with a reference that doesn't depend on the model being right. They run on every change to the simulator's code.

  1. With the last service down, retrying at every hop multiplies load on it by attempts^depth.
// /simulators/service-mesh
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { simulate, type Params } from '../../src/lib/sims/mesh.ts';

const base: Params = { depth: 4, instances: 5, bad: 1, failRate: 1, down: false, attempts: 3, retryAt: 'every', backoff: 25, outlier: false, consecutive: 5, ejectMs: 30000, maxEjectPct: 10, serviceMs: 5, proxyMs: 0.5, rate: 20, seconds: 60, seed: 1 };

test('with the last service down, retrying at every hop multiplies load on it by attempts^depth', () => {
	for (const a of [1, 2, 3]) for (const d of [1, 2, 3, 4]) {
		const r = simulate({ ...base, down: true, attempts: a, depth: d });
		assert.ok(Math.abs(r.perRequest - a ** d) < 1e-9, `${a} attempts, depth ${d}: ${r.perRequest} calls per request`);
		assert.equal(r.ok, 0);
	}
});

Shared helpers: tests/sims/check.ts. The model under test is imported from src/lib/sims/.

Published