gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf15-navigate3b3e451f|||PR ident#36 navigate to the app instead of location.assignmref15-navigate/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

  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre
  • 675493b1ident#42: editing an identity upserts the one edited row (face editIdentity answers { identity, row }); a create or delete keeps the whole list because the rows' position-dependent parts (default, Delete, Identity n) changemre
  • 45e55303ident#42: an app write patches one row: upsert on create, edit and new secret, one-argument remove on delete; the faces answer the changed app (or the deleted id), not the whole listmre
  • 991641d4Merge branch 'f10-access' into mainIdent
  • e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre
  • df7696dbident#34: tests: access ticks selector quoting fixmre
  • 7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre
  • 69b0a0ceident#34: access: the pick buttons use Style.pickCard instead of class pickmre
  • dc702419Merge branch 'f9-choose' into mainIdent
  • 8caec771|||PR ident#34 restore .choose hookmre
  • 0dbff960Merge branch 'f8-shared' into mainIdent
  • d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre