// waitUntilDead will block until the specified store is marked as dead. func waitUntilDead(t *testing.T, mc *hlc.ManualClock, sp *StorePool, storeID roachpb.StoreID) { lastTime := timeutil.Now() util.SucceedsSoon(t, func() error { curTime := timeutil.Now() mc.Increment(curTime.UnixNano() - lastTime.UnixNano()) lastTime = curTime sp.mu.RLock() defer sp.mu.RUnlock() store, ok := sp.mu.storeDetails[storeID] if !ok { t.Fatalf("store %s isn't in the pool's store list", storeID) } exitcode := store.dead if exitcode { return nil } return errors.New("store not marked as dead yet") }) }
// expireNextReservation advances the manual clock to one nanosecond passed the // next expiring reservation and waits until exactly one reservation has expired. func expireNextReservation(t *testing.T, mc *hlc.ManualClock, b *bookie) { b.mu.Lock() nextExpiredReservation := b.mu.queue.peek() if nextExpiredReservation == nil { t.Fatalf("expected at least one reservation, but there are none") } expectedExpires := len(b.mu.queue) - 1 // Set the clock to after next timeout. mc.Set(nextExpiredReservation.expireAt.WallTime + 1) b.mu.Unlock() util.SucceedsSoon(t, func() error { b.mu.Lock() defer b.mu.Unlock() if expectedExpires != len(b.mu.queue) { nextExpiredReservation := b.mu.queue.peek() return fmt.Errorf("expiration has not yet occurred, next expiration in %s for rangeID:%d", nextExpiredReservation.expireAt, nextExpiredReservation.RangeID) } return nil }) }