Make workspace authoring transitions and typed invocation coherent
This commit is contained in:
@@ -11,9 +11,14 @@ test("authoring lock excludes concurrent mutations and survives owner death", as
|
||||
const root = await mkdtemp(path.join(os.tmpdir(), "qx-lock-test-"));
|
||||
context.after(() => rm(root, {recursive: true, force: true}));
|
||||
const filename = path.join(root, "lock");
|
||||
const events: string[] = [];
|
||||
let queued: Promise<void>;
|
||||
await withFileLock(filename, async () => {
|
||||
await assert.rejects(withFileLock(filename, async () => assert.fail("concurrent mutation")), /Another authoring command/);
|
||||
queued = withFileLock(filename, async () => {events.push("second");});
|
||||
events.push("first");
|
||||
});
|
||||
await queued!;
|
||||
assert.deepEqual(events, ["first", "second"]);
|
||||
const module = new URL("../src/capability-language/file-lock.js", import.meta.url).href;
|
||||
const owner = spawn(process.execPath, ["--input-type=module", "-e",
|
||||
`import {withFileLock} from ${JSON.stringify(module)}; await withFileLock(${JSON.stringify(filename)}, async () => {process.stdout.write('ready'); await new Promise(() => {});});`],
|
||||
@@ -23,11 +28,7 @@ test("authoring lock excludes concurrent mutations and survives owner death", as
|
||||
const exited = once(owner, "exit");
|
||||
owner.kill("SIGKILL");
|
||||
await exited;
|
||||
// EOF release happens in the helper; wait a bounded amount for scheduling.
|
||||
let acquired = false;
|
||||
for (let attempt = 0; attempt < 30 && !acquired; attempt++) {
|
||||
try { await withFileLock(filename, async () => {acquired = true;}); }
|
||||
catch (error) { if (!/Another authoring command/.test(String(error))) throw error; }
|
||||
}
|
||||
await withFileLock(filename, async () => {acquired = true;});
|
||||
assert.equal(acquired, true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user