jukebox
All repositories: gitoria
3.0 KB
import assert from 'node:assert/strict';import http from 'node:http';import { spawn, spawnSync } from 'node:child_process';import { readlinkSync } from 'node:fs';import { once } from 'node:events';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';const HERE = dirname(fileURLToPath(import.meta.url));const ROOT = resolve(HERE, '../../..');const PORT = Number(process.env.HL_TEST_PORT || 32069);const BIN = process.env.HL_BIN || resolve(ROOT, 'native/zig-out/bin/hybriel');const child = spawn(BIN, [resolve(HERE, 'sse-close.hl')], { cwd: ROOT, env: process.env });let log = '', checks = 0;child.stdout.on('data', d => { log += d; });child.stderr.on('data', d => { log += d; });const streams = [];const sleep = ms => new Promise(r => setTimeout(r, ms));async function waitFor(fn) {for (let i = 0; i < 250; i++) { if (await fn()) return; await sleep(20); }throw new Error('timeout\n' + log);}const get = path => fetch(`http://127.0.0.1:${PORT}${path}`).then(r => r.text());function check(a, b) { assert.deepEqual(a, b); checks++; }async function stream() {const p = { data: '', ended: false };streams.push(p);p.req = http.get(`http://127.0.0.1:${PORT}/stream`, res => {p.res = res;res.on('data', d => { p.data += d; });res.on('end', () => { p.ended = true; });res.on('error', e => { p.error = e; });});p.req.on('error', e => { p.error = e; });await waitFor(() => /data: (\d+)\n\n/.test(p.data));p.id = Number(p.data.match(/data: (\d+)\n\n/)[1]);return p;}try {await waitFor(async () => { try { return await get('/') === '0'; } catch { return false; } });const a = await stream(), b = await stream();check(await get('/'), '2');check(await get(`/alive?id=${a.id}`), 'true');check(await get(`/close?id=${a.id}`), 'true');await waitFor(() => a.ended);check(a.ended, true);check(await get('/'), '1');check(await get(`/alive?id=${a.id}`), 'false');check(await get(`/send?id=${a.id}`), 'false');check(await get(`/close?id=${a.id}`), 'false');check(await get(`/send?id=${b.id}`), 'true');check(await get('/broadcast'), '1');await waitFor(() => b.data.includes('data: broadcast\n\n'));check(b.data, `: connected\n\ndata: ${b.id}\n\ndata: direct\n\ndata: broadcast\n\n`);const c = await stream();check(c.id > Math.max(a.id, b.id), true);check(await get('/'), '2');check(await get(`/send?id=${a.id}`), 'false');check(await get(`/send?id=${c.id}`), 'true');await waitFor(() => c.data.includes('data: direct\n\n'));check(c.data, `: connected\n\ndata: ${c.id}\n\ndata: direct\n\n`);check(await get(`/alive?id=${b.id}`), 'true');console.log(`ok sse-close: ${checks} checks`);} finally {for (const p of streams) { p.res?.destroy(); p.req.destroy(); }if (child.exitCode === null && child.signalCode === null) {assert.equal(readlinkSync(`/proc/${child.pid}/cwd`), ROOT);spawnSync('ss', ['-ltnp', `sport = ${PORT}`]);const stopped = once(child, 'exit'); child.kill('SIGTERM'); await stopped;}}
Branches
Latest commits
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre
- 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
- 6422a020Sync media-player at 51c3818mre
- b582ba1cVendor complete Hybriel day72 plugin setmre
- 02dccbc9Merge branch 'records-1119' into mainJukebox
- a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
- fc7db075Merge branch 'reconnect-retry' into mainJukebox
- ac6f4c6fL2: plain declaration for a in pickedNextmre
- 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
- 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
- 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
- 1f0cd77bMerge branch 'records-day41' into mainJukebox
- 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
- 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
- 04f5d9d5Merge branch 'day41' into mainJukebox
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre