Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions vscode-ext/test/surface-ids.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawnSync } from 'node:child_process';
import { chmod, mkdir, readFile, rm, utimes, writeFile } from 'node:fs/promises';
import { chmod, mkdir, readFile, rename, rm, utimes, writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

Expand Down Expand Up @@ -33,6 +33,13 @@ async function holdLock(pid: number, token = 'theirs') {
await mkdir(lock());
await writeFile(path.join(lock(), 'owner.json'), JSON.stringify({ pid, token }));
}
/** Release that lock as a holder does: moved aside in one step, so a waiter
* never renames its own lock onto the emptied directory mid-removal. */
async function releaseLock() {
const aside = `${lock()}.released`;
await rename(lock(), aside);
await rm(aside, { recursive: true });
}
const lockToken = async () => (JSON.parse(await readFile(path.join(lock(), 'owner.json'), 'utf8')) as { token: string }).token;
/** A pid no process has: one that just exited. */
const deadPid = () => spawnSync(process.execPath, ['-e', '']).pid!;
Expand Down Expand Up @@ -86,7 +93,7 @@ describe('createSurfaceIdAllocator', () => {
void waiting.then(() => { settled = true; });
await new Promise((resolve) => setTimeout(resolve, 50));
expect(settled).toBe(false);
await rm(lock(), { recursive: true });
await releaseLock();
expect(await waiting).toEqual(['surface:1']);
await expect(readFile(path.join(lock(), 'owner.json'))).rejects.toThrow();
});
Expand Down
Loading