mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-21 04:10:47 +02:00
close Windows lock handoff races
This commit is contained in:
@@ -37,6 +37,7 @@ describe("runtime cleanup boundary", () => {
|
||||
const home = await temporaryHome();
|
||||
const lockPath = path.join(home, "locks", "windows-race.lock");
|
||||
let mkdirAttempts = 0;
|
||||
let releaseOptions: Record<string, unknown> | undefined;
|
||||
const release = await acquireLock(lockPath, {
|
||||
platform: "win32",
|
||||
mkdir: async (target: string, options: Record<string, unknown>) => {
|
||||
@@ -45,9 +46,25 @@ describe("runtime cleanup boundary", () => {
|
||||
}
|
||||
return fs.mkdir(target, options);
|
||||
},
|
||||
rm: async (target: string, options: Record<string, unknown>) => {
|
||||
releaseOptions = options;
|
||||
return fs.rm(target, options);
|
||||
},
|
||||
});
|
||||
expect(mkdirAttempts).toBe(2);
|
||||
await release();
|
||||
expect(releaseOptions).toMatchObject({ recursive: true, force: true, maxRetries: 5, retryDelay: 50 });
|
||||
|
||||
await expect(acquireLock(path.join(home, "locks", "permanently-denied.lock"), {
|
||||
platform: "win32",
|
||||
transientPermissionMs: 20,
|
||||
mkdir: async (target: string, options: Record<string, unknown>) => {
|
||||
if (target.endsWith("permanently-denied.lock")) {
|
||||
throw Object.assign(new Error("permanent permission denial"), { code: "EPERM" });
|
||||
}
|
||||
return fs.mkdir(target, options);
|
||||
},
|
||||
})).rejects.toMatchObject({ code: "EPERM" });
|
||||
|
||||
let renameAttempts = 0;
|
||||
await renameWithRetry("source", "destination", {
|
||||
|
||||
@@ -390,7 +390,7 @@ describe("GStack 2 managed runtime installer", () => {
|
||||
const originalMode = (await fs.stat(cli)).mode & 0o777;
|
||||
await fs.chmod(cli, originalMode === 0o600 ? 0o644 : 0o600);
|
||||
await expect(validateRuntimeBundle(result.path, { version: "2.0.0", platform: "win32" })).resolves.toBe(true);
|
||||
await expect(validateRuntimeBundle(result.path, { version: "2.0.0" })).rejects.toMatchObject({
|
||||
await expect(validateRuntimeBundle(result.path, { version: "2.0.0", platform: "linux" })).rejects.toMatchObject({
|
||||
code: "INSTALL_VALIDATION_FAILED",
|
||||
});
|
||||
await fs.chmod(cli, originalMode);
|
||||
|
||||
Reference in New Issue
Block a user