Пример #1
0
// expireNextBooking advances the manual clock to one nanosecond passed the
// next expiring booking and waits until exactly the number of expired bookings
// is equal to expireCount.
func expireNextBooking(t *testing.T, mc *hlc.ManualClock, b *bookie, expireCount int) {
	b.mu.Lock()
	nextExpiredBooking := b.mu.queue.peek()
	expectedExpires := len(b.mu.queue) - expireCount
	b.mu.Unlock()
	if nextExpiredBooking == nil {
		return
	}
	// Set the clock to after next timeout.
	mc.Set(nextExpiredBooking.expireAt.WallTime + 1)

	util.SucceedsSoon(t, func() error {
		b.mu.Lock()
		defer b.mu.Unlock()
		if expectedExpires != len(b.mu.queue) {
			nextExpiredBooking := b.mu.queue.peek()
			return fmt.Errorf("expiration has not occured yet, next expiration in %s for rangeID:%d",
				nextExpiredBooking.expireAt, nextExpiredBooking.reservation.rangeID)
		}
		return nil
	})
}
Пример #2
0
// 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
	})
}