@@ -21,6 +21,9 @@ func TestAdd(t *testing.T) {
21
21
cks .Add (model .TimeFromUnixNano (time .Hour .Nanoseconds ()) + TimeResolution + 1 )
22
22
require .Equal (t , 2 , len (cks ))
23
23
require .Equal (t , 1 , len (cks [1 ].Samples ))
24
+ cks .Add (model .TimeFromUnixNano (time .Hour .Nanoseconds ()) - TimeResolution )
25
+ require .Equal (t , 2 , len (cks ))
26
+ require .Equalf (t , 1 , len (cks [1 ].Samples ), "Older samples should not be added if they arrive out of order" )
24
27
}
25
28
26
29
func TestIterator (t * testing.T ) {
@@ -52,6 +55,7 @@ func TestForRange(t *testing.T) {
52
55
c * Chunk
53
56
start model.Time
54
57
end model.Time
58
+ step model.Time
55
59
expected []logproto.PatternSample
56
60
}{
57
61
{
@@ -180,6 +184,28 @@ func TestForRange(t *testing.T) {
180
184
{Timestamp : 4 , Value : 10 },
181
185
},
182
186
},
187
+ {
188
+ name : "Out-of-order samples generate nil result" ,
189
+ c : & Chunk {Samples : []logproto.PatternSample {
190
+ {Timestamp : 5 , Value : 2 },
191
+ {Timestamp : 3 , Value : 2 },
192
+ }},
193
+ start : 4 ,
194
+ end : 6 ,
195
+ expected : nil ,
196
+ },
197
+ {
198
+ name : "Internally out-of-order samples generate nil result" ,
199
+ c : & Chunk {Samples : []logproto.PatternSample {
200
+ {Timestamp : 1 , Value : 2 },
201
+ {Timestamp : 5 , Value : 2 },
202
+ {Timestamp : 3 , Value : 2 },
203
+ {Timestamp : 7 , Value : 2 },
204
+ }},
205
+ start : 2 ,
206
+ end : 6 ,
207
+ expected : nil ,
208
+ },
183
209
}
184
210
185
211
for _ , tc := range testCases {
0 commit comments