// Accept returns true if currently can accept request. func (l *Limiter) Accept() bool { l.l.Lock() t := hal.Now() r := t.Sub(l.ring[l.tail]) > l.d if r { l.ring[l.tail] = t l.tail-- if l.tail == -1 { l.tail = len(l.ring) - 1 } } l.l.Unlock() return r }
assertTimeMocked = func() { assert.Equal(t(), reflect.ValueOf(now), reflect.ValueOf(hal.Now)) } ) bdd.BeforeEach(func() { reset.Enable() }) bdd.AfterEach(func() { reset.Disable() }) bdd.It("Default Time", func() { Install() assert.Equal(t(), time.Date(2016, 1, 1, 0, 0, 0, 0, time.Local), hal.Now()) }) bdd.It("Install", func() { assertTimeNotMocked() Install() assertTimeMocked() }) bdd.It("Auto install", func() { assertTimeNotMocked() Set(time.Unix(11000000, 0)) assertTimeMocked() }) bdd.It("Set", func() {