-
Notifications
You must be signed in to change notification settings - Fork 11
/
sweeper_test.go
51 lines (39 loc) · 956 Bytes
/
sweeper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package flow
import (
"testing"
"time"
"github.com/benbjohnson/clock"
)
var mockClock = clock.NewMock()
func init() {
SetClock(mockClock)
}
// regression test for libp2p/go-libp2p-core#65
func TestIdleInconsistency(t *testing.T) {
r := new(MeterRegistry)
m1 := r.Get("first")
m2 := r.Get("second")
m3 := r.Get("third")
m1.Mark(10)
m2.Mark(20)
m3.Mark(30)
// make m1 and m3 go idle
for i := 0; i < 30; i++ {
mockClock.Add(time.Second)
m2.Mark(1)
}
mockClock.Add(time.Second)
// re-activate m3
m3.Mark(20)
mockClock.Add(time.Second)
// check the totals
if total := r.Get("first").Snapshot().Total; total != 10 {
t.Errorf("expected first total to be 10, got %d", total)
}
if total := r.Get("second").Snapshot().Total; total != 50 {
t.Errorf("expected second total to be 50, got %d", total)
}
if total := r.Get("third").Snapshot().Total; total != 50 {
t.Errorf("expected third total to be 50, got %d", total)
}
}