Make only the first rebuild wait in the newest-change test
The test gated the slow rebuild on `written.length === 0`, but the first rebuild is suspended at that await, so the second rebuild saw a length of 0 too and waited on the same promise. Both then resolved in call order and the assertion held even with no serialization at all — the test could not fail. Count rebuilds instead, and wait for the first one to have actually started before submitting the second change. Verified both directions against a non-serialized queue: the old shape passed, the new one produces ['newer-change', 'older-change'] and fails. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lcj4iQ3fBxMwAu2rf4zLbC
This commit is contained in:
parent
2b9a5c4112
commit
d346922c11
1 changed files with 11 additions and 4 deletions
|
|
@ -83,13 +83,20 @@ it('writes the newest change last when an earlier rebuild is slower', async () =
|
|||
// batches tests pin the scheduling on its own; this pins the outcome through
|
||||
// the watcher wiring, which is the shape the bug was reported in.
|
||||
let written: string[] = []
|
||||
let rebuildCount = 0
|
||||
let startFirstRebuild!: () => void
|
||||
let firstRebuildStarted = new Promise<void>((resolve) => (startFirstRebuild = resolve))
|
||||
let releaseSlowRebuild!: () => void
|
||||
let slowRebuildCanFinish = new Promise<void>((resolve) => (releaseSlowRebuild = resolve))
|
||||
|
||||
let queue = serializeBatches<string>(async (files) => {
|
||||
// Make the *first* rebuild the slow one. Without serialization the second
|
||||
// rebuild finishes first and this stale result lands on top of it.
|
||||
if (written.length === 0) await slowRebuildCanFinish
|
||||
// Only the *first* rebuild is slow. Counting rebuilds rather than writes
|
||||
// matters: the first rebuild is suspended below, so a write-count check
|
||||
// would also suspend the second one and the test would pass unserialized.
|
||||
if (rebuildCount++ === 0) {
|
||||
startFirstRebuild()
|
||||
await slowRebuildCanFinish
|
||||
}
|
||||
written.push(files.at(-1)!)
|
||||
})
|
||||
let fake = fakeWatcher()
|
||||
|
|
@ -105,7 +112,7 @@ it('writes the newest change last when an earlier rebuild is slower', async () =
|
|||
)
|
||||
|
||||
await fake.callbacks[0](null, [{ type: 'update', path: 'older-change' }])
|
||||
await nextTask()
|
||||
await firstRebuildStarted
|
||||
await fake.callbacks[0](null, [{ type: 'update', path: 'newer-change' }])
|
||||
await nextTask()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue