diff --git a/tests/vfs/vfs.unit.test.ts b/tests/vfs/vfs.unit.test.ts index c2f49c9f..cc201de5 100644 --- a/tests/vfs/vfs.unit.test.ts +++ b/tests/vfs/vfs.unit.test.ts @@ -396,19 +396,19 @@ describe('VirtualFileSystem - Production Tests', () => { await vfs.mkdir('/cached') await vfs.writeFile(path, 'cached content') - // First read (cold cache) - const start1 = Date.now() - await vfs.readFile(path) - const time1 = Date.now() - start1 + // Prime the path cache + verify the content round-trips. + expect((await vfs.readFile(path)).toString()).toBe('cached content') - // Second read (warm cache) - const start2 = Date.now() - await vfs.readFile(path) - const time2 = Date.now() - start2 + // Cached repeated access is sub-millisecond. Average many reads so the result + // doesn't hinge on Date.now()'s millisecond rounding of a single sub-ms op — the + // old cold-vs-warm compare spuriously failed when both rounded to 0/1ms. A + // generous absolute bound still catches a regression to per-read disk/index work. + const ITERATIONS = 100 + const start = performance.now() + for (let i = 0; i < ITERATIONS; i++) await vfs.readFile(path) + const avgWarmMs = (performance.now() - start) / ITERATIONS - // Cache should make second read faster - expect(time2).toBeLessThanOrEqual(time1) - console.log(`Cold read: ${time1}ms, Warm read: ${time2}ms`) + expect(avgWarmMs).toBeLessThan(5) }) })