@@ -339,12 +339,18 @@ func TestAsyncComputeMissingRanges(t *testing.T) {
339339 err := db .ApplyChangesetAsync (31 , changesets )
340340 require .NoError (t , err )
341341
342- // Wait a bit for the async computation to complete
343- time .Sleep (200 * time .Millisecond )
342+ // Wait for the async computation to complete with retries
343+ var lastHashed int64
344+ for retries := 0 ; retries < 50 ; retries ++ {
345+ lastHashed , err = db .GetLastRangeHashed ()
346+ require .NoError (t , err )
347+ if lastHashed >= 30 {
348+ break
349+ }
350+ time .Sleep (20 * time .Millisecond )
351+ }
344352
345353 // We should now have hashed up to version 30 (3 complete ranges)
346- lastHashed , err := db .GetLastRangeHashed ()
347- require .NoError (t , err )
348354 assert .Equal (t , int64 (30 ), lastHashed )
349355
350356 // Apply more changesets to get to version 40
@@ -353,12 +359,17 @@ func TestAsyncComputeMissingRanges(t *testing.T) {
353359 require .NoError (t , err )
354360 }
355361
356- // Wait a bit for async computation
357- time .Sleep (500 * time .Millisecond )
362+ // Wait for async computation to complete with retries
363+ for retries := 0 ; retries < 50 ; retries ++ {
364+ lastHashed , err = db .GetLastRangeHashed ()
365+ require .NoError (t , err )
366+ if lastHashed >= 40 {
367+ break
368+ }
369+ time .Sleep (20 * time .Millisecond )
370+ }
358371
359372 // We should now have hashed up to version 40
360- lastHashed , err = db .GetLastRangeHashed ()
361- require .NoError (t , err )
362373 assert .Equal (t , int64 (40 ), lastHashed )
363374}
364375
0 commit comments