-
Notifications
You must be signed in to change notification settings - Fork 20
/
rebuilding_test.go
70 lines (55 loc) · 1.16 KB
/
rebuilding_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package quamina
import (
"fmt"
"testing"
)
func TestLiveRatioTrigger(t *testing.T) {
r := newLiveRatioTrigger(0.5, 2)
s := &prunerStats{}
if r.rebuild(false, s) {
t.Fatal("shouldn't have fired")
}
s.Live = 5
s.Deleted = 3
if r.rebuild(true, s) {
t.Fatal("shouldn't have fired")
}
if !r.rebuild(false, s) {
t.Fatal("should have fired")
}
s.Live = 1
if r.rebuild(false, s) {
t.Fatal("shouldn't have fired")
}
}
func TestNeverTrigger(t *testing.T) {
r := newNeverTrigger()
s := &prunerStats{
Live: 42,
Deleted: 17,
}
if r.rebuild(false, s) {
t.Fatal("you only had one job")
}
}
// sane verifies that certain prunerStats are not negative.
//
// The types in question aren't uint(64) but maybe they should be.
func (s prunerStats) sane() error {
if s.Live < 0 {
return fmt.Errorf("prunerStats.Live is negative")
}
if s.Added < 0 {
return fmt.Errorf("prunerStats.Added is negative")
}
if s.Deleted < 0 {
return fmt.Errorf("prunerStats.Deleted is negative")
}
if s.Filtered < 0 {
return fmt.Errorf("prunerStats.Filtered is negative")
}
return nil
}
func (m *prunerMatcher) checkStats() error {
return m.getStats().sane()
}