gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit942ac995942ac995status: paused workers statemre942ac995/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

  • 942ac995status: paused workers statemre
  • 44b934e5log: respawn cleanupmre
  • 03a80097Log: Anton GC A/Bmre
  • c7cdef62Log: Apollo STOP, workers pausedmre
  • d0c083fbLog: usage stopmre
  • c6d464e5Log: Apollo GO backlog, AP56 and BS1 startedmre
  • 1eb6f1a1Missions AP56, BS1mre
  • 4871f8adLog: AP52 live on day52, browser gate greenmre
  • d9bf2988Merge ap52: day52, tracker#58 server argument, #51 modal close rule, #56 keyed season rowsmre
  • c4a60ef2Log: RT52 retest passed, AP52 startedmre
  • 83760a55Browser gate: search results belong to the address form of the typed text (tracker#52 navigate replace)mre
  • 6e951d91AP52: show-page rows are keyed records; closing a season is one upsert and removes (tracker#56, hybriel#331)mre
  • 3bb4ccddAP52: modal close button refers to its nested rule with Style.buttonModalX (tracker#51, hybriel#333)mre
  • ba16933fAP52: login callback and title route are static handlers taking the server as third argument (tracker#58, hybriel#332)mre
  • 85153900AP52: re-vendor Hybriel set day52 (source 77cfca31, bin 0a8ed496)mre
  • 7c051eddLog: hybriel#338 answermre
  • d049b8b8Log: HM50 live, #52 donemre
  • 6d05fa37Log: HM50 Part A mergedmre
  • 1c7dab74HM50: the shell reads the framework's online state, netProbe removed (tracker#55)mre
  • e8b91697HM50: search address follows the text via navigate(path, replace = true) (tracker#52)mre