Skip to content

Commit a004e18

Browse files
authored
test(sessions): publish concurrency markers atomically (#99212)
1 parent a51b06f commit a004e18

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/config/sessions/session-accessor.reply-init-concurrency.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ async function waitForFile(filePath) {
8484
}
8585
8686
async function writeJsonFile(filePath, value) {
87-
await fs.writeFile(filePath, \`\${JSON.stringify(value, null, 2)}\\n\`, "utf8");
87+
// The parent treats file existence as the readiness signal, so publish atomically.
88+
const tempPath = filePath + "." + process.pid + ".tmp";
89+
await fs.writeFile(tempPath, \`\${JSON.stringify(value, null, 2)}\\n\`, "utf8");
90+
await fs.rename(tempPath, filePath);
8891
}
8992
9093
const storePath = process.env.REPLY_INIT_STORE_PATH;
@@ -192,7 +195,6 @@ describe("reply session initialization concurrency", () => {
192195
stdio: ["ignore", "pipe", "pipe"],
193196
},
194197
);
195-
196198
await waitForFile(readyPath);
197199
const snapshot = await readJsonFile<{ currentEntry?: unknown; revision: string }>(readyPath);
198200
expect(snapshot.revision).toBe(JSON.stringify({ sessionId: "existing-session" }));

0 commit comments

Comments
 (0)