gitoria
All repositories: gitoria
3.4 KB
// Mirrors ws-handshake-order.mjs: exercise the built plugin over real sockets.import { spawn, spawnSync } from 'node:child_process';import { readlinkSync } from 'node:fs';import { once } from 'node:events';import assert from 'node:assert/strict';import { fileURLToPath } from 'node:url';import { resolve, dirname } from 'node:path';const HERE = dirname(fileURLToPath(import.meta.url));const ROOT = resolve(HERE, '../../..');const PORT = Number(process.env.HL_TEST_PORT || 30090);const BIN = process.env.HL_BIN || resolve(ROOT, 'native/zig-out/bin/hybriel');const server = spawn(BIN, [resolve(HERE, 'two-ws-servers.hl')], { cwd: ROOT, env: { ...process.env, HL_TEST_PORT: String(PORT) }, stdio: ['ignore', 'pipe', 'pipe'] });let log = '', checks = 0;server.stdout.on('data', d => { log += d; });server.stderr.on('data', d => { log += d; });const peers = [];const sleep = ms => new Promise(r => setTimeout(r, ms));const get = (port, path = '/') => fetch(`http://127.0.0.1:${port}${path}`).then(r => r.text());function check(actual, expected) { assert.deepEqual(actual, expected); checks++; }async function waitFor(fn) {for (let i = 0; i < 150; i++) { if (await fn()) return; await sleep(20); }throw new Error('timeout\n' + log);}function peer(port) {const ws = new WebSocket(`ws://127.0.0.1:${port}/`);ws.messages = [];ws.addEventListener('message', e => ws.messages.push(String(e.data)));peers.push(ws);return ws;}try {await waitFor(async () => { try { return await get(PORT) === '0:0'; } catch { return false; } });const a1 = peer(PORT), a2 = peer(PORT), b = peer(PORT + 1);await waitFor(() => peers.every(p => p.messages.length >= 1));check(a1.messages, ['open:A']); check(a2.messages, ['open:A']); check(b.messages, ['open:B']);a1.send('one'); a2.send('two'); b.send('three');await waitFor(() => peers.every(p => p.messages.length >= 2));check(a1.messages, ['open:A', 'A:one']); check(a2.messages, ['open:A', 'A:two']); check(b.messages, ['open:B', 'B:three']);check(await get(PORT, '/broadcast'), '2');await waitFor(() => a1.messages.length === 3 && a2.messages.length === 3);check(await get(PORT + 1, '/broadcast'), '1');await waitFor(() => b.messages.length === 3);await sleep(100);check(a1.messages, ['open:A', 'A:one', 'broadcast:A']);check(a2.messages, ['open:A', 'A:two', 'broadcast:A']);check(b.messages, ['open:B', 'B:three', 'broadcast:B']);a1.close(); await once(a1, 'close');await waitFor(async () => await get(PORT) === '1:0'); check(await get(PORT + 1), '1:0');b.close(); await once(b, 'close');await waitFor(async () => await get(PORT + 1) === '1:1'); check(await get(PORT), '1:1');const b2 = peer(PORT + 1); await waitFor(() => b2.messages.length === 1); check(b2.messages, ['open:B']);await get(PORT, '/stop');b2.send('survives'); await waitFor(() => b2.messages.length === 2); check(b2.messages, ['open:B', 'B:survives']);check(await get(PORT + 1, '/broadcast'), '1'); await waitFor(() => b2.messages.length === 3);check(b2.messages, ['open:B', 'B:survives', 'broadcast:B']);console.log(`ok two-ws-servers: ${checks} checks`);} finally {for (const p of peers) p.close();if (server.exitCode === null) {const stopped = once(server, 'exit');assert.equal(readlinkSync(`/proc/${server.pid}/cwd`), ROOT);spawnSync('ss', ['-ltnp', `( sport = ${PORT} or sport = ${PORT + 1} )`]);server.kill('SIGTERM');await stopped;}}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
- 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
- 155861f6Merge branch 'w52-person-approval' into mainGitoria
- b5435de8|||PR person approvals: second Kunibert round (#52)mre
- 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre
- 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
- 83f0c953Report person approval verificationmre
- 3ae94b86Record browser failures and verify owned tab cleanupmre
- 54eec687Gate person approvals and merge alternativesmre
- 12b08829Add person approvals for pull request headsmre
- 55c84779Merge branch 'gp-gate-ports' into mainGitoria
- 57af42bbREADME: point to deploy.sh for the port listmre
- d63375d2README: gate commands with explicit portsmre
- feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
- 6cc1f943Merge branch 'records-1112' into mainGitoria
- 9448c438|||PR records: LOG, missions and reports since 11-09mre
- 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
- 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
- 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
- 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria