test(8.0): de-flake the VFS path-cache timing assertion
`should cache paths for fast repeated access` compared a single cold vs warm readFile with Date.now() (ms resolution). Both reads are sub-millisecond, so the warm read intermittently measured 1ms vs the cold 0ms and the `time2 <= time1` assertion failed on rounding noise — a non-deterministic gate that blocked a clean release. Replace it with the average of 100 warm reads via performance.now() against a generous absolute bound (cached path reads are sub-ms), plus a content round-trip check. Same intent (cached access is fast), no single-shot ms flake. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
1c363e8c4b
commit
0e8972c6fa
1 changed files with 11 additions and 11 deletions
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue