gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3059f86c3059f86cMerge branch 'records-design-rule' into mainTracker3059f86c/plugins/fs/tests/exclusive-create.mjs

2.5 KB

  1. // A barrier releases 16 independent processes against one absent path.
  2. import { spawn, spawnSync } from 'node:child_process';
  3. import { mkdtempSync, writeFileSync, existsSync, readFileSync, rmSync } from 'node:fs';
  4. import { join, resolve } from 'node:path';
  5. import assert from 'node:assert/strict';
  6. const root = resolve(import.meta.dirname, '../../..');
  7. const bin = process.env.HL_BIN || join(root, 'native/zig-out/bin/hybriel');
  8. const work = mkdtempSync(join(process.env.TMPDIR || '/tmp', 'hl-exclusive-'));
  9. const children = [];
  10. try {
  11. const src = join(work, 'claim.hl');
  12. writeFileSync(src, `import { createFile, exists } from 'hl:fs'
  13. import { args } from 'hl:proc'
  14. import { sleep } from 'hl:time'
  15. a = args()
  16. createFile(a[0] + '.ready.' + a[1], '')
  17. while (!exists(a[0] + '.go')) { sleep(0.005) }
  18. console.log(createFile(a[0], a[1]))
  19. `);
  20. const native = join(work, 'claim');
  21. const built = spawnSync(bin, ['--native', src, '-o', native], { encoding: 'utf8' });
  22. assert.equal(built.status, 0, `${built.error || ""}${built.stdout || ""}${built.stderr || ""}`);
  23. for (const engine of ['run', 'native']) {
  24. const path = join(work, engine);
  25. const promises = Array.from({ length: 16 }, (_, i) => {
  26. const child = spawn(engine === 'run' ? bin : native, engine === 'run' ? [src, path, String(i)] : [path, String(i)]);
  27. children.push(child);
  28. return new Promise((resolve, reject) => {
  29. let output = '';
  30. child.stdout.on('data', b => { output += b; });
  31. child.stderr.on('data', b => { output += b; });
  32. child.on('error', reject);
  33. child.on('close', code => resolve({ code, output: output.trim(), i }));
  34. });
  35. });
  36. const deadline = Date.now() + 30000;
  37. while (!Array.from({ length: 16 }, (_, i) => existsSync(path + '.ready.' + i)).every(Boolean)) {
  38. assert.ok(Date.now() < deadline, 'workers did not reach barrier');
  39. await new Promise(r => setTimeout(r, 20));
  40. }
  41. writeFileSync(path + '.go', '');
  42. const answers = await Promise.all(promises);
  43. for (const a of answers) { assert.equal(a.code, 0, a.output); assert.match(a.output, /^(true|false)$/); }
  44. const winners = answers.filter(a => a.output === 'true');
  45. assert.equal(winners.length, 1);
  46. assert.equal(readFileSync(path, 'utf8'), String(winners[0].i));
  47. console.log(`exclusive-create ${engine}: 1/16 won, winner content preserved`);
  48. }
  49. } finally {
  50. for (const c of children) if (c.exitCode === null) c.kill('SIGKILL');
  51. await Promise.all(children.filter(c => c.exitCode === null).map(c => new Promise(r => c.once('close', r))));
  52. rmSync(work, { recursive: true, force: true });
  53. }

Branches

Latest commits

  • 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
  • 4e018678|||PR deploy.sh: gates use Tracker's ports 8716-8719 and LC_ALL=C; README: 2 backups keptTracker
  • 0b86324aMerge branch 'records-dp73' into mainTracker
  • 9ce5f59b|||PR records: DP73 live 613ae0e; deploy.sh keeps 2 backupsTracker
  • 613ae0ecMerge branch 'bs3' into mainTracker
  • 1383264b|||PR BS3: keep shared synchronous sorting fastTracker
  • 63e5ba1a|||PR BS3: guard boot imports and share resumable sort buffersTracker
  • 310613f1Merge branch 'records-dp72' into mainTracker