mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
test(filesystem): verify commit cancellation closes its parent descriptor (#12814)
This commit is contained in:
1 parent
9ab18ba1da
commit
84ee3c1edc
2 files changed
+37
-38
No files matched your search
@@ -39,30 +39,24 @@ describe("safe artifact output cleanup", () => {
|
||||
expect(await readdir(output)).toEqual([]);
|
||||
await tree.closeHandles();
|
||||
});
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
"closes the parent descriptor when the output disappears before commit",
|
||||
async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const output = join(parent, "published");
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
await rm(output, { recursive: true });
|
||||
await expect(tree.commit()).rejects.toThrow();
|
||||
const targets = await Promise.all(
|
||||
(await readdir("/proc/self/fd")).map((fd) =>
|
||||
readlink(`/proc/self/fd/${fd}`).catch(() => undefined),
|
||||
),
|
||||
);
|
||||
expect(targets.filter((target) => target === parent)).toEqual([]);
|
||||
const failure = await tree.rollback().catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(failure).toMatchObject({ cleanup: { resources: [output] } });
|
||||
expect(tree.cleanup).toEqual({
|
||||
status: "incomplete",
|
||||
residualPaths: ["published"],
|
||||
});
|
||||
await rm(parent, { recursive: true, force: true });
|
||||
},
|
||||
);
|
||||
it("keeps cleanup incomplete when the owned root disappears before commit", async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-");
|
||||
const output = join(parent, "published");
|
||||
const tree = await SafeOutputTree.create(output);
|
||||
await rm(output, { recursive: true });
|
||||
|
||||
await expect(tree.commit()).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expect(tree.rollback()).rejects.toMatchObject({
|
||||
reason: "integrity",
|
||||
integrityCheck: "output-lifecycle",
|
||||
cause: { code: "ENOENT" },
|
||||
cleanup: { resources: [output] },
|
||||
});
|
||||
expect(tree.cleanup).toEqual({
|
||||
status: "incomplete",
|
||||
residualPaths: ["published"],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("safe artifact output file identity admission", () => {
|
||||
|
||||
@@ -19,8 +19,9 @@ const injectedFilesystemFailures = vi.hoisted(() => ({
|
||||
| undefined,
|
||||
blockCloseRetries: false,
|
||||
chmodNext: false,
|
||||
syncAbortAfter: undefined as AbortController | undefined,
|
||||
syncCount: 0,
|
||||
parentSync: undefined as
|
||||
| { path: string; controller: AbortController; handle?: FileHandle }
|
||||
| undefined,
|
||||
rootIdentityPath: undefined as string | undefined,
|
||||
}));
|
||||
|
||||
@@ -56,13 +57,13 @@ vi.mock("node:fs/promises", async (importOriginal) => {
|
||||
await close();
|
||||
};
|
||||
}
|
||||
if (injectedFilesystemFailures.syncAbortAfter !== undefined) {
|
||||
const parentSync = injectedFilesystemFailures.parentSync;
|
||||
if (parentSync !== undefined && args[0] === parentSync.path) {
|
||||
const sync = handle.sync.bind(handle);
|
||||
handle.sync = async () => {
|
||||
await sync();
|
||||
injectedFilesystemFailures.syncCount += 1;
|
||||
if (injectedFilesystemFailures.syncCount === 2)
|
||||
injectedFilesystemFailures.syncAbortAfter?.abort();
|
||||
parentSync.handle = handle;
|
||||
parentSync.controller.abort();
|
||||
};
|
||||
}
|
||||
return handle;
|
||||
@@ -124,7 +125,7 @@ describe("safe artifact output close failures", () => {
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"keeps the tree unpublished when cancellation arrives during commit durability",
|
||||
"closes the parent descriptor and keeps output unpublished after cancellation during durability",
|
||||
async () => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-cancel-");
|
||||
const output = join(parent, "unpublished");
|
||||
@@ -134,19 +135,23 @@ describe("safe artifact output close failures", () => {
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.byteLength,
|
||||
});
|
||||
const controller = new AbortController();
|
||||
injectedFilesystemFailures.syncCount = 0;
|
||||
injectedFilesystemFailures.syncAbortAfter = controller;
|
||||
const parentSync: NonNullable<
|
||||
typeof injectedFilesystemFailures.parentSync
|
||||
> = { path: parent, controller: new AbortController() };
|
||||
injectedFilesystemFailures.parentSync = parentSync;
|
||||
try {
|
||||
await expect(tree.commit(controller.signal)).rejects.toMatchObject({
|
||||
await expect(
|
||||
tree.commit(parentSync.controller.signal),
|
||||
).rejects.toMatchObject({
|
||||
reason: "cancelled",
|
||||
});
|
||||
expect(parentSync.handle?.fd).toBe(-1);
|
||||
expect(tree.published).toBe(false);
|
||||
} finally {
|
||||
injectedFilesystemFailures.syncAbortAfter = undefined;
|
||||
injectedFilesystemFailures.syncCount = 0;
|
||||
injectedFilesystemFailures.parentSync = undefined;
|
||||
await tree.rollback();
|
||||
}
|
||||
expect(await tree.rollback()).toMatchObject({ status: "complete" });
|
||||
expect(tree.cleanup).toMatchObject({ status: "complete" });
|
||||
await expect(access(output)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user