gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchrecords-hm55b2ae3b80dc|||PR records: HM55b briefTrackerrecords-hm55b2/plugins/http1/tests/two-ws-servers.mjs

3.4 KB

  1. // Mirrors ws-handshake-order.mjs: exercise the built plugin over real sockets.
  2. import { spawn, spawnSync } from 'node:child_process';
  3. import { readlinkSync } from 'node:fs';
  4. import { once } from 'node:events';
  5. import assert from 'node:assert/strict';
  6. import { fileURLToPath } from 'node:url';
  7. import { resolve, dirname } from 'node:path';
  8. const HERE = dirname(fileURLToPath(import.meta.url));
  9. const ROOT = resolve(HERE, '../../..');
  10. const PORT = Number(process.env.HL_TEST_PORT || 30090);
  11. const BIN = process.env.HL_BIN || resolve(ROOT, 'native/zig-out/bin/hybriel');
  12. const server = spawn(BIN, [resolve(HERE, 'two-ws-servers.hl')], { cwd: ROOT, env: { ...process.env, HL_TEST_PORT: String(PORT) }, stdio: ['ignore', 'pipe', 'pipe'] });
  13. let log = '', checks = 0;
  14. server.stdout.on('data', d => { log += d; });
  15. server.stderr.on('data', d => { log += d; });
  16. const peers = [];
  17. const sleep = ms => new Promise(r => setTimeout(r, ms));
  18. const get = (port, path = '/') => fetch(`http://127.0.0.1:${port}${path}`).then(r => r.text());
  19. function check(actual, expected) { assert.deepEqual(actual, expected); checks++; }
  20. async function waitFor(fn) {
  21. for (let i = 0; i < 150; i++) { if (await fn()) return; await sleep(20); }
  22. throw new Error('timeout\n' + log);
  23. }
  24. function peer(port) {
  25. const ws = new WebSocket(`ws://127.0.0.1:${port}/`);
  26. ws.messages = [];
  27. ws.addEventListener('message', e => ws.messages.push(String(e.data)));
  28. peers.push(ws);
  29. return ws;
  30. }
  31. try {
  32. await waitFor(async () => { try { return await get(PORT) === '0:0'; } catch { return false; } });
  33. const a1 = peer(PORT), a2 = peer(PORT), b = peer(PORT + 1);
  34. await waitFor(() => peers.every(p => p.messages.length >= 1));
  35. check(a1.messages, ['open:A']); check(a2.messages, ['open:A']); check(b.messages, ['open:B']);
  36. a1.send('one'); a2.send('two'); b.send('three');
  37. await waitFor(() => peers.every(p => p.messages.length >= 2));
  38. check(a1.messages, ['open:A', 'A:one']); check(a2.messages, ['open:A', 'A:two']); check(b.messages, ['open:B', 'B:three']);
  39. check(await get(PORT, '/broadcast'), '2');
  40. await waitFor(() => a1.messages.length === 3 && a2.messages.length === 3);
  41. check(await get(PORT + 1, '/broadcast'), '1');
  42. await waitFor(() => b.messages.length === 3);
  43. await sleep(100);
  44. check(a1.messages, ['open:A', 'A:one', 'broadcast:A']);
  45. check(a2.messages, ['open:A', 'A:two', 'broadcast:A']);
  46. check(b.messages, ['open:B', 'B:three', 'broadcast:B']);
  47. a1.close(); await once(a1, 'close');
  48. await waitFor(async () => await get(PORT) === '1:0'); check(await get(PORT + 1), '1:0');
  49. b.close(); await once(b, 'close');
  50. await waitFor(async () => await get(PORT + 1) === '1:1'); check(await get(PORT), '1:1');
  51. const b2 = peer(PORT + 1); await waitFor(() => b2.messages.length === 1); check(b2.messages, ['open:B']);
  52. await get(PORT, '/stop');
  53. b2.send('survives'); await waitFor(() => b2.messages.length === 2); check(b2.messages, ['open:B', 'B:survives']);
  54. check(await get(PORT + 1, '/broadcast'), '1'); await waitFor(() => b2.messages.length === 3);
  55. check(b2.messages, ['open:B', 'B:survives', 'broadcast:B']);
  56. console.log(`ok two-ws-servers: ${checks} checks`);
  57. } finally {
  58. for (const p of peers) p.close();
  59. if (server.exitCode === null) {
  60. const stopped = once(server, 'exit');
  61. assert.equal(readlinkSync(`/proc/${server.pid}/cwd`), ROOT);
  62. spawnSync('ss', ['-ltnp', `( sport = ${PORT} or sport = ${PORT + 1} )`]);
  63. server.kill('SIGTERM');
  64. await stopped;
  65. }
  66. }

Branches

Latest commits

  • ae3b80dc|||PR records: HM55b briefTracker
  • 7ef3cb3bMerge branch 'records-st55' into mainTracker
  • fec2e080|||PR records: STATUS HM55Tracker
  • 8e174918Merge branch 'records-hm55b' into mainTracker
  • b1ecee57|||PR records: HM55 stateTracker
  • 28eab08cMerge branch 'records-hm55' into mainTracker
  • d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
  • 3059f86cMerge branch 'records-design-rule' into mainTracker
  • 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
  • d1390692Merge branch 'records-dp75b' into mainTracker
  • a4d1a7d2|||PR records: later steps checked, branch auditTracker
  • e070e16fMerge branch 'records-dp75' into mainTracker
  • 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
  • bfc4ea4dMerge branch 'ap62' into mainTracker
  • 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker
  • b9c7c3c8Merge branch 'records-dp74' into mainTracker
  • 85cfb4ae|||PR records: AP61 day61, DP74 liveTracker
  • b1496147Merge branch 'ap61' into mainTracker
  • 2047955bMerge branch 'u12-gateports' into mainTracker
  • c8da40f3|||PR AP61: re-vendor Hybriel set day61 (source a05af47c, bin a11042e5)Tracker