@@ -201,13 +201,26 @@ describe('FileDocStore', () => {
201201 const doc = new Y . Doc ( )
202202 await store . attachRoom ( NAME , doc )
203203
204- // Build a streak of two failures (retries back off ~0.5s, then ~1s).
204+ // Build a streak of two failures. Waited for rather than slept through: on a loaded machine a
205+ // fixed window can pass with fewer failures than the streak this test needs.
205206 state . backing ! . readerClosed = true
206- await sleep ( 800 )
207- // Redis comes back. Wait past the pending backoff so a read actually lands — and it returns
208- // nothing new, which is the idle case this test is about.
207+ const beforeStreak = state . backing ! . reads
208+ await vi . waitFor ( ( ) => expect ( state . backing ! . reads ) . toBeGreaterThanOrEqual ( beforeStreak + 2 ) , {
209+ timeout : 5000 ,
210+ interval : 25 ,
211+ } )
212+
213+ // Redis comes back. Wait for a read to actually LAND — `xRead` only throws while the reader is
214+ // closed, so the next one to arrive is the idle read whose return ends the streak. Sleeping a
215+ // fixed 1s instead lets a slow machine finish the window with the pending backoff still
216+ // outstanding, leaving the streak alive and the assertion below measuring a delay this test
217+ // never meant to produce.
209218 state . backing ! . readerClosed = false
210- await sleep ( 1000 )
219+ const beforeIdle = state . backing ! . reads
220+ await vi . waitFor ( ( ) => expect ( state . backing ! . reads ) . toBeGreaterThan ( beforeIdle ) , {
221+ timeout : 5000 ,
222+ interval : 25 ,
223+ } )
211224
212225 // A fresh blip must retry at the START of the backoff curve, not partway up it. Assert the DELAY
213226 // itself: counting attempts inside a fixed window cannot tell the two apart, because the jittered
0 commit comments