Files
usenet-indexer/tests/unit/edge/throttle.spec.ts
Daan MeijerandClaude Opus 5.5 42b6cac3ee
Test and deploy / test (push) Successful in 38s
Test and deploy / deploy (push) Skipped
Rebuild: edge:node --max-mbit caps a node's download
For workers on a shared line (poweredge-kantoor: 160 Mbit/s): the range
stream is read at most at the cap, TCP holds the coordinator back. The
cap is the node's, split over its processes (also EDGE_MAX_MBIT).
REBUILD.md: where workers run (connections set the speed; remote workers
take CPU off homelab).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 09:01:57 +02:00

17 lines
686 B
TypeScript

import { test } from '@japa/runner'
import { throttle } from '#lib/edge/index'
test.group('edge / throttle', () => {
test('passes everything on, at most the given rate after the first second', async ({ assert }) => {
const pieces = Array.from({ length: 30 }, (_, i) => new Uint8Array(1000).fill(i))
const started = Date.now()
const out: Uint8Array[] = []
// 30,000 bytes at 20,000 B/s: the first 20,000 at once, the rest over ~0.5 s.
for await (const piece of throttle(pieces, 20_000)) out.push(piece)
const seconds = (Date.now() - started) / 1000
assert.deepEqual(out, pieces)
assert.isAtLeast(seconds, 0.45)
assert.isBelow(seconds, 1.2)
})
})