About: how pages are checked

tests/sims/cwnd.test.ts

The automated tests for the /simulators/tcp-congestion 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. Kurose and Ross exercise: Reno with ssthresh 32, losses at rounds 16, 22 and 26.
  2. Tahoe drops to 1 on triple duplicate ACKs, and slow start can overshoot ssthresh when not capped.
  3. CUBIC (RFC 9438): the window starts at 0.7 W_max and reaches W_max at time K.
// /simulators/tcp-congestion
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { run, roundOfSegment, cubicK, cubicW } from '../../src/lib/sims/cwnd.ts';

test('Kurose and Ross exercise: Reno with ssthresh 32, losses at rounds 16, 22 and 26', () => {
	const R = run({ variant: 'reno', initial: 1, ssthresh: 32, rounds: 27, losses: { 16: 'dup3', 22: 'timeout', 26: 'dup3' }, capAtSsthresh: true, plus3: false, floor2: false });
	assert.equal(R[16].cwnd, 21);
	assert.equal(R[17].ssthresh, 21);
	assert.equal(R[22].cwnd, 1);
	assert.equal(R[23].ssthresh, 13);
	assert.equal(roundOfSegment(R, 70), 7);
	assert.equal(R[26].cwnd, 4);
	assert.equal(R[26].ssthresh, 4);
});

test('Tahoe drops to 1 on triple duplicate ACKs, and slow start can overshoot ssthresh when not capped', () => {
	const T = run({ variant: 'tahoe', initial: 1, ssthresh: 8, rounds: 12, losses: { 6: 'dup3' }, capAtSsthresh: true, plus3: false, floor2: false });
	assert.equal(T.map((r) => r.cwnd).join(), '1,2,4,8,9,10,1,2,4,5,6,7');
	const C = run({ variant: 'tahoe', initial: 1, ssthresh: 6, rounds: 5, losses: {}, capAtSsthresh: false, plus3: false, floor2: false });
	assert.equal(C.map((r) => r.cwnd).join(), '1,2,4,8,9');
});

test('CUBIC (RFC 9438): the window starts at 0.7 W_max and reaches W_max at time K', () => {
	for (const w of [10, 100, 1000]) {
		assert.ok(Math.abs(cubicW(cubicK(w), w) - w) < 1e-9);
		assert.ok(Math.abs(cubicW(0, w) - 0.7 * w) < 1e-9);
	}
});

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

Published