gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/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

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • b2572b34Merge branch 'v59-day59' into mainIdent
  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 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