mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 18:51:39 +00:00
Refactor throttle timer
This commit is contained in:
@ -41,6 +41,7 @@ func TestThrottle(test *testing.T) {
|
||||
|
||||
ms := 50
|
||||
delay := time.Duration(ms) * time.Millisecond
|
||||
shortwait := time.Duration(ms/2) * time.Millisecond
|
||||
longwait := time.Duration(2) * delay
|
||||
t := NewThrottleTimer("foo", delay)
|
||||
|
||||
@ -65,6 +66,21 @@ func TestThrottle(test *testing.T) {
|
||||
time.Sleep(longwait)
|
||||
assert.Equal(2, c.Count())
|
||||
|
||||
// keep cancelling before it is ready
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Set()
|
||||
time.Sleep(shortwait)
|
||||
t.Unset()
|
||||
}
|
||||
time.Sleep(longwait)
|
||||
assert.Equal(2, c.Count())
|
||||
|
||||
// a few unsets do nothing...
|
||||
for i := 0; i < 5; i++ {
|
||||
t.Unset()
|
||||
}
|
||||
assert.Equal(2, c.Count())
|
||||
|
||||
// send 12, over 2 delay sections, adds 3
|
||||
short := time.Duration(ms/5) * time.Millisecond
|
||||
for i := 0; i < 13; i++ {
|
||||
@ -74,5 +90,6 @@ func TestThrottle(test *testing.T) {
|
||||
time.Sleep(longwait)
|
||||
assert.Equal(5, c.Count())
|
||||
|
||||
close(t.Ch)
|
||||
stopped := t.Stop()
|
||||
assert.True(stopped)
|
||||
}
|
||||
|
Reference in New Issue
Block a user