mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 20:21:56 +00:00
Revert "Refactor throttle timer"
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type thCounter struct {
|
||||
input <-chan struct{}
|
||||
input chan struct{}
|
||||
mtx sync.Mutex
|
||||
count int
|
||||
}
|
||||
@@ -31,9 +31,6 @@ func (c *thCounter) Count() int {
|
||||
// Read should run in a go-routine and
|
||||
// updates count by one every time a packet comes in
|
||||
func (c *thCounter) Read() {
|
||||
// note, since this channel never closes, this will never end
|
||||
// if thCounter was used in anything beyond trivial test cases.
|
||||
// it would have to be smarter.
|
||||
for range c.input {
|
||||
c.Increment()
|
||||
}
|
||||
@@ -44,7 +41,6 @@ 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)
|
||||
|
||||
@@ -69,21 +65,6 @@ 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++ {
|
||||
@@ -93,6 +74,5 @@ func TestThrottle(test *testing.T) {
|
||||
time.Sleep(longwait)
|
||||
assert.Equal(5, c.Count())
|
||||
|
||||
stopped := t.Stop()
|
||||
assert.True(stopped)
|
||||
close(t.Ch)
|
||||
}
|
||||
|
Reference in New Issue
Block a user