func (*queueSuite) TestRemove(c *gc.C) { clock := coretesting.NewClock(time.Time{}) now := clock.Now() s := timequeue.New(clock) s.Add("k0", "v0", now.Add(3*time.Second)) s.Add("k1", "v1", now.Add(2*time.Second)) s.Remove("k0") assertReady(c, s, clock /* nothing */) clock.Advance(3 * time.Second) assertReady(c, s, clock, "v1") }
func (*queueSuite) TestAdd(c *gc.C) { clock := coretesting.NewClock(time.Time{}) now := clock.Now() s := timequeue.New(clock) s.Add("k0", "v0", now.Add(3*time.Second)) s.Add("k1", "v1", now.Add(1500*time.Millisecond)) s.Add("k2", "v2", now.Add(2*time.Second)) clock.Advance(time.Second) // T+1 assertReady(c, s, clock /* nothing */) clock.Advance(time.Second) // T+2 assertReady(c, s, clock, "v1", "v2") assertReady(c, s, clock /* nothing */) clock.Advance(500 * time.Millisecond) // T+2.5 assertReady(c, s, clock /* nothing */) clock.Advance(time.Second) // T+3.5 assertReady(c, s, clock, "v0") }
func (*queueSuite) TestNext(c *gc.C) { clock := coretesting.NewClock(time.Time{}) now := clock.Now() s := timequeue.New(clock) s.Add("k0", "v0", now.Add(3*time.Second)) s.Add("k1", "v1", now.Add(1500*time.Millisecond)) s.Add("k2", "v2", now.Add(2*time.Second)) s.Add("k3", "v3", now.Add(2500*time.Millisecond)) assertNextOp(c, s, clock, 1500*time.Millisecond) clock.Advance(1500 * time.Millisecond) assertReady(c, s, clock, "v1") clock.Advance(500 * time.Millisecond) assertNextOp(c, s, clock, 0) assertReady(c, s, clock, "v2") s.Remove("k3") clock.Advance(2 * time.Second) // T+4 assertNextOp(c, s, clock, 0) assertReady(c, s, clock, "v0") }
// NewSchedule constructs a new schedule, using the given Clock for the Next // and Add methods. func NewSchedule(clock clock.Clock) *Schedule { return &Schedule{time: clock, q: timequeue.New(clock)} }
func (*queueSuite) TestRemoveKeyNotFound(c *gc.C) { s := timequeue.New(coretesting.NewClock(time.Time{})) s.Remove("0") // does not explode }
func (*queueSuite) TestReadyNoEvents(c *gc.C) { s := timequeue.New(coretesting.NewClock(time.Time{})) ready := s.Ready(time.Now()) c.Assert(ready, gc.HasLen, 0) }
func (*queueSuite) TestNextNoEvents(c *gc.C) { s := timequeue.New(coretesting.NewClock(time.Time{})) next := s.Next() c.Assert(next, gc.IsNil) }