Skip to content

Commit f1246e3

Browse files
committed
test(usage): land the forged rewrite on a later timestamp tick
On kernels with coarse timestamps a write in the same tick as the cached read keeps the same ctime, so the test repeats the rewrite until ctime moves, as any real rewrite does.
1 parent c993d62 commit f1246e3

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

‎apps/server/src/usage/usageTranscriptReader.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,17 @@ describe("SQLite usage readers", () => {
776776
const cache = makeAntigravityUsageCache();
777777
assert.deepStrictEqual((await readAntigravityUsage(dir, 0, cache)).errors, []);
778778

779-
const { size } = await NodeFSP.stat(path);
780-
await NodeFSP.writeFile(path, Buffer.alloc(size));
781-
await NodeFSP.utimes(path, 1780000000, 1780000000);
779+
// ctime has the kernel's timestamp granularity, which can be a few
780+
// milliseconds, so repeat the forged rewrite until it lands on a later tick
781+
// than the cached read, as any real rewrite does.
782+
const cached = await NodeFSP.stat(path);
783+
do {
784+
await NodeFSP.writeFile(path, Buffer.alloc(cached.size));
785+
await NodeFSP.utimes(path, 1780000000, 1780000000);
786+
} while ((await NodeFSP.stat(path)).ctimeMs === cached.ctimeMs);
787+
const restored = await NodeFSP.stat(path);
788+
assert.strictEqual(restored.size, cached.size);
789+
assert.strictEqual(restored.mtimeMs, cached.mtimeMs);
782790
const next = await readAntigravityUsage(dir, 0, cache);
783791
assert.deepStrictEqual(next.errors, [path]);
784792
assert.deepStrictEqual(

0 commit comments

Comments
 (0)