gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit384d3d23384d3d23|||PR give calendar months their own addressAtlas384d3d23/plugins/http1/tests/on-error-answers.mjs

4.1 KB

  1. // #285: exercise real sockets through the run form and a native executable.
  2. import { spawn, execFileSync } from 'node:child_process';
  3. import { once } from 'node:events';
  4. import { mkdtempSync, rmSync, readlinkSync } from 'node:fs';
  5. import { tmpdir } from 'node:os';
  6. import { resolve, join, dirname } from 'node:path';
  7. import { fileURLToPath } from 'node:url';
  8. import assert from 'node:assert/strict';
  9. const here = dirname(fileURLToPath(import.meta.url));
  10. const root = resolve(here, '../../..');
  11. const bin = process.env.HL_BIN || join(root, 'native/zig-out/bin/hybriel');
  12. const fixture = join(here, 'on-error-answers.hl');
  13. const port = Number(process.env.HL_TEST_PORT || 31910);
  14. const work = mkdtempSync(join(tmpdir(), 'on-error-answers-'));
  15. let checks = 0;
  16. const sleep = ms => new Promise(r => setTimeout(r, ms));
  17. try {
  18. const native = join(work, 'server');
  19. execFileSync(bin, ['--native', fixture, '-o', native, '--quiet'], { cwd: root, timeout: 180000 });
  20. for (const [name, cmd, args] of [['run', bin, [fixture]], ['native', native, []]]) {
  21. const child = spawn(cmd, args, { cwd: root, env: { ...process.env, HL_TEST_PORT: String(port) }, stdio: ['ignore', 'pipe', 'pipe'] });
  22. const exited = once(child, 'exit');
  23. let log = '';
  24. child.stdout.on('data', d => { log += d });
  25. child.stderr.on('data', d => { log += d });
  26. const request = async path => {
  27. const r = await fetch(`http://127.0.0.1:${port}${path}`, { signal: AbortSignal.timeout(3000) });
  28. return { status: r.status, body: await r.text(), type: r.headers.get('content-type'), fallback: r.headers.get('x-fallback') };
  29. };
  30. try {
  31. let up = false;
  32. for (let i = 0; i < 150; i++) {
  33. if (child.exitCode !== null) break;
  34. try { if ((await request('/health')).body === 'healthy') { up = true; break } } catch {}
  35. await sleep(100);
  36. }
  37. assert.ok(up, `${name} failed to boot: ${log}`);
  38. for (const [path, status, body, type] of [
  39. ['/text', 200, 'fallback', 'text/plain'],
  40. ['/json', 200, '{"ok":true,"items":[1,2]}', 'application/json'],
  41. ['/status', 503, 'unavailable', null],
  42. ['/bytes', 200, 'raw', 'application/octet-stream'],
  43. ['/empty', 200, '', 'text/plain'],
  44. ['/false', 200, 'false', 'application/json'],
  45. ['/zero', 200, '0', 'application/json'],
  46. ['/sent', 202, 'sent', null],
  47. ]) {
  48. const r = await request(path);
  49. assert.equal(r.status, status, `${name} ${path}`);
  50. assert.equal(r.body, body, `${name} ${path}`);
  51. if (type) assert.ok(r.type?.startsWith(type), `${name} ${path} content type: ${r.type}`);
  52. if (path === '/status') assert.equal(r.fallback, 'yes');
  53. checks++;
  54. }
  55. for (const path of ['/null', '/none']) {
  56. const r = await request(path);
  57. assert.equal(r.status, 500);
  58. assert.match(r.body, /route:/);
  59. assert.match(r.body, /on-error-answers.hl:/);
  60. checks++;
  61. }
  62. assert.equal((await request('/health')).body, 'healthy');
  63. assert.doesNotMatch(log, /UNREACHABLE/);
  64. assert.equal((log.match(/^hook$/gm) || []).length, 10);
  65. assert.equal((log.match(/^handled$/gm) || []).length, 10);
  66. checks++;
  67. await request('/fatal').catch(() => {});
  68. const [code] = await Promise.race([exited, sleep(5000).then(() => { throw new Error('fatal handler did not stop') })]);
  69. assert.equal(code, 1, log);
  70. assert.match(log, /error-handler-fault/);
  71. checks++;
  72. console.log(`${name}: 12/12`);
  73. } finally {
  74. if (child.exitCode === null && child.signalCode === null) {
  75. // Only our child, and verify its cwd before signalling it.
  76. const sockets = execFileSync('ss', ['-ltnp', `sport = :${port}`], { encoding: 'utf8' });
  77. if (sockets.includes('LISTEN')) assert.ok(sockets.includes(`pid=${child.pid},`), 'listener belongs to our child');
  78. let cwd;
  79. try { cwd = readlinkSync(`/proc/${child.pid}/cwd`) }
  80. catch (e) { if (e.code !== 'ENOENT') throw e }
  81. if (cwd !== undefined) { assert.equal(cwd, root); child.kill('SIGTERM') }
  82. await exited;
  83. }
  84. }
  85. }
  86. console.log(`on-error-answers: ${checks}/24`);
  87. } finally { rmSync(work, { recursive: true, force: true }) }

Branches

Latest commits

  • 384d3d23|||PR give calendar months their own addressAtlas
  • fff2f537Merge branch 'calendar31-lib' into mainAtlas
  • 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
  • a753b0ab|||PR move shared calendar logic to libAtlas
  • b32a921dMerge branch 'vendor-day72' into mainAtlas
  • 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
  • 53f5464dMerge branch 'calendar26-day73' into mainAtlas
  • 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
  • ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
  • cab224a1Re-vendor calendar to verified Hybriel day73Atlas
  • f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
  • 66341793|||PR Vendor Hybriel day61Atlas
  • 36fc596bMerge branch 'vendor-day59' into mainAtlas
  • b37cc1da|||PR Vendor Hybriel day59Atlas
  • 05665102Merge branch 'vendor-day56' into mainAtlas
  • 687296fb|||PR Vendor Hybriel day56Atlas
  • a6166d4eMerge branch 'hl-standard-3' into mainAtlas
  • 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
  • add4b499|||PR Make calendar day actions keyboard accessibleAtlas
  • 79e49b4dMerge branch 'hl-standard' into mainAtlas