gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit63e5ba1a63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker63e5ba1a/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

  • 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker
  • 310613f1Merge branch 'records-dp72' into mainTracker
  • 6f7b61ba|||PR records: deploy-swap fix live, Kunibert findingsTracker
  • c41587d2Merge branch 'bs2' into mainTracker
  • 0dd538a6|||PR BS2: finish the boot index in slices so a booting instance keeps answeringTracker
  • 019d5cedMerge branch 'records-1110' into mainTracker
  • f88ae8b9|||PR records: day56 toggle live, reviewTracker
  • b6b3bb4dMerge branch 'ap56e' into mainTracker
  • 29a26da9|||PR AP56e: guard hidden show helpers during session syncTracker
  • 7c9ec236|||PR AP56e: re-vendor Hybriel set day56 (source 36ae83a8, bin c1f595a2)Tracker
  • 4b54f6f9Merge branch 'records-audit' into mainTracker
  • cab4a3bc|||PR records: branch audit, PR-onlyTracker
  • 641e1c4cMerge branch 'records-dp71' into mainTracker
  • 85a6e9f5|||PR records: DP71 checked in ChromeTracker
  • f5be5f18records: gitoria PR-only planTracker
  • 46a37036records: DP71 liveTracker
  • 3bcb7039Status/log: DP71 in progressTracker
  • 5b3a5693Log: SR1b merged via PR 2, DP71 startedTracker
  • 783957c2Merge branch 'sr1-search' into mainTracker
  • 792b9652README: search results come from the routeTracker