gitoria

components

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchvl27-resetkeya06fc778Reset virtual-list window when the host changes resetKeyAtlasvl27-resetkey/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

  • a06fc778Reset virtual-list window when the host changes resetKeyAtlas
  • 3aab598cRe-vendor complete Hybriel day73 set for virtual-list resetAtlas
  • 337ca075MD1 gate check measures frames in the page, not milliseconds from outside, and takes the middle load (components#30)mre
  • f5f131c5Record AP29 autoplay comparisons and passing gatesmre
  • 51c38187Gate media autoplay on first load and after client mountmre
  • a3f2223dRecord successful B44 deployment and live proofmre
  • 06c1e021Record passing B44 browser rerunmre
  • c9861533Record B44 component proof and browser gate blockermre
  • 1b7413beIgnore detached media events and space demo option outputsmre
  • ca3b4959Re-vendor complete Hybriel plugins and runtime to day44mre
  • df9e7df9Last-item checks run in the browser gate (components#26 fixed on day41); media-player loop is a plain Booleanmre
  • 895a5afcRe-vendor complete Hybriel plugins and runtime to day41mre
  • 16006bb3Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 88397fc3Re-vendor complete Hybriel plugins and runtime to day39mre
  • 9b872cedRecord IC28 deployment and live icon verificationmre
  • 46fefaa7Count the icons entry in the offline home-page checkmre
  • c7e14cabRecord IC28 rerun and unchanged-main baseline comparisonmre
  • 5e090ffdRecord IC28 review evidence and gate resultsmre
  • adfe2c4dAdd shuffle, repeat and repeatOne shared iconsmre
  • c96709c8media-player: skip = false and repeat = 'one' options (jukebox#19)mre