@@ -34,7 +34,9 @@ func (c *Checker) Add(ts uint32, val float64) {
34
34
// from to is the range that gets requested from AggMetric
35
35
// first/last is what we use as data range to compare to (both inclusive)
36
36
// these may be different because AggMetric returns broader rangers (due to packed format),
37
- func (c * Checker ) Verify (from , to , first , last uint32 ) {
37
+ func (c * Checker ) Verify (primary bool , from , to , first , last uint32 ) {
38
+ currentClusterStatus := clusterStatus .IsPrimary ()
39
+ clusterStatus .Set (primary )
38
40
_ , iters := c .agg .Get (from , to )
39
41
// we don't do checking or fancy logic, it is assumed that the caller made sure first and last are ts of actual points
40
42
var pi int // index of first point we want
@@ -61,6 +63,7 @@ func (c *Checker) Verify(from, to, first, last uint32) {
61
63
if index != pj {
62
64
c .t .Fatalf ("not all values returned. missing %v" , c .points [index :pj + 1 ])
63
65
}
66
+ clusterStatus .Set (currentClusterStatus )
64
67
}
65
68
66
69
func TestAggMetric (t * testing.T ) {
@@ -72,52 +75,55 @@ func TestAggMetric(t *testing.T) {
72
75
73
76
// basic case, single range
74
77
c .Add (101 , 101 )
75
- c .Verify (100 , 200 , 101 , 101 )
78
+ c .Verify (true , 100 , 200 , 101 , 101 )
76
79
c .Add (105 , 105 )
77
- c .Verify (100 , 199 , 101 , 105 )
80
+ c .Verify (true , 100 , 199 , 101 , 105 )
78
81
c .Add (115 , 115 )
79
82
c .Add (125 , 125 )
80
83
c .Add (135 , 135 )
81
- c .Verify (100 , 199 , 101 , 135 )
84
+ c .Verify (true , 100 , 199 , 101 , 135 )
82
85
83
86
// add new ranges, aligned and unaligned
84
87
c .Add (200 , 200 )
85
88
c .Add (315 , 315 )
86
- c .Verify (100 , 399 , 101 , 315 )
89
+ c .Verify (true , 100 , 399 , 101 , 315 )
90
+
91
+ // verify as secondary node. Data from the first chunk should not be returned.
92
+ c .Verify (false , 100 , 399 , 200 , 315 )
87
93
88
94
// get subranges
89
- c .Verify (120 , 299 , 101 , 200 )
90
- c .Verify (220 , 299 , 200 , 200 )
91
- c .Verify (312 , 330 , 315 , 315 )
95
+ c .Verify (true , 120 , 299 , 101 , 200 )
96
+ c .Verify (true , 220 , 299 , 200 , 200 )
97
+ c .Verify (true , 312 , 330 , 315 , 315 )
92
98
93
99
// border dancing. good for testing inclusivity and exclusivity
94
- c .Verify (100 , 199 , 101 , 135 )
95
- c .Verify (100 , 200 , 101 , 135 )
96
- c .Verify (100 , 201 , 101 , 200 )
97
- c .Verify (198 , 199 , 101 , 135 )
98
- c .Verify (199 , 200 , 101 , 135 )
99
- c .Verify (200 , 201 , 200 , 200 )
100
- c .Verify (201 , 202 , 200 , 200 )
101
- c .Verify (299 , 300 , 200 , 200 )
102
- c .Verify (300 , 301 , 315 , 315 )
100
+ c .Verify (true , 100 , 199 , 101 , 135 )
101
+ c .Verify (true , 100 , 200 , 101 , 135 )
102
+ c .Verify (true , 100 , 201 , 101 , 200 )
103
+ c .Verify (true , 198 , 199 , 101 , 135 )
104
+ c .Verify (true , 199 , 200 , 101 , 135 )
105
+ c .Verify (true , 200 , 201 , 200 , 200 )
106
+ c .Verify (true , 201 , 202 , 200 , 200 )
107
+ c .Verify (true , 299 , 300 , 200 , 200 )
108
+ c .Verify (true , 300 , 301 , 315 , 315 )
103
109
104
110
// skipping
105
111
c .Add (510 , 510 )
106
112
c .Add (512 , 512 )
107
- c .Verify (100 , 599 , 101 , 512 )
113
+ c .Verify (true , 100 , 599 , 101 , 512 )
108
114
109
115
// basic wraparound
110
116
c .Add (610 , 610 )
111
117
c .Add (612 , 612 )
112
118
c .Add (710 , 710 )
113
119
c .Add (712 , 712 )
114
120
// TODO would be nice to test that it panics when requesting old range. something with recover?
115
- //c.Verify(100, 799, 101, 512)
121
+ //c.Verify(true, 100, 799, 101, 512)
116
122
117
123
// largest range we have so far
118
- c .Verify (300 , 799 , 315 , 712 )
124
+ c .Verify (true , 300 , 799 , 315 , 712 )
119
125
// a smaller range
120
- c .Verify (502 , 799 , 510 , 712 )
126
+ c .Verify (true , 502 , 799 , 510 , 712 )
121
127
122
128
// the circular buffer had these ranges:
123
129
// 100 200 300 skipped 500
@@ -130,7 +136,7 @@ func TestAggMetric(t *testing.T) {
130
136
// but we just check we only get this point
131
137
c .Add (1299 , 1299 )
132
138
// TODO: implement skips and enable this
133
- // c.Verify(800, 1299, 1299, 1299)
139
+ // c.Verify(true, 800, 1299, 1299, 1299)
134
140
}
135
141
136
142
// basic expected RAM usage for 1 iteration (= 1 days)
0 commit comments