Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Fix flaky live-process discovery test (#11418)

Trevor Manzcc1682681fe4
diff --git a/packages/client/src/__tests__/discovery.test.ts b/packages/client/src/__tests__/discovery.test.ts
index 779a02aa69..260f08d754 100644
--- a/packages/client/src/__tests__/discovery.test.ts
+++ b/packages/client/src/__tests__/discovery.test.ts
@@ -237,14 +237,20 @@ describe.skipIf(!["darwin", "linux"].includes(process.platform))(
await vi.importActual<typeof import("node:child_process")>(
"node:child_process",
);
- runPs.mockImplementation(promisify(execFile));
+ const exec = promisify(execFile);
+ runPs.mockImplementation(exec);
+ // Node's uptime starts after the OS process does. Use the OS start
+ // time so that startup overhead cannot exceed the one-second tolerance.
+ const { stdout } = await exec(
+ "/bin/ps",
+ ["-p", String(process.pid), "-o", "lstart="],
+ { env: { ...process.env, LC_ALL: "C", TZ: "UTC" } },
+ );
const live = {
...record,
process: {
pid: process.pid,
- started_at: new Date(
- Date.now() - process.uptime() * 1000,
- ).toISOString(),
+ started_at: new Date(`${stdout.trim()} UTC`).toISOString(),
},
};
await write(live);