Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 4585ff7

Browse files
committed
add tests
1 parent b7973a3 commit 4585ff7

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

api/query_engine_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,28 @@ func TestAlignRequestsHuh(t *testing.T) {
414414
)
415415
}
416416

417+
func TestAlignRequestsDifferentReadyStates(t *testing.T) {
418+
testAlign([]models.Req{
419+
reqRaw(test.GetMKey(1), 100, 300, 800, 1, consolidation.Avg, 0, 0),
420+
},
421+
[][]conf.Retention{
422+
{
423+
conf.NewRetentionMT(1, 300, 120, 5, 0), // TTL not good enough
424+
conf.NewRetentionMT(5, 450, 600, 4, math.MaxUint32), // TTL good, but not ready
425+
conf.NewRetentionMT(10, 460, 600, 3, 150), // TTL good, but not ready since long enough
426+
conf.NewRetentionMT(20, 470, 600, 2, 101), // TTL good, but not ready since long enough
427+
conf.NewRetentionMT(60, 480, 600, 1, 100), // TTL good and ready since long enough
428+
},
429+
},
430+
[]models.Req{
431+
reqOut(test.GetMKey(1), 100, 300, 800, 1, consolidation.Avg, 0, 0, 4, 60, 480, 60, 1),
432+
},
433+
nil,
434+
500,
435+
t,
436+
)
437+
}
438+
417439
var hour uint32 = 60 * 60
418440
var day uint32 = 24 * hour
419441

conf/retention_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package conf
2+
3+
import (
4+
"math"
5+
"reflect"
6+
"testing"
7+
)
8+
9+
func TestParseRetentions(t *testing.T) {
10+
cases := []struct {
11+
in string
12+
err bool
13+
out []Retention
14+
}{
15+
{
16+
in: "1s:1d:1h:2,1m:8d:4h:2:1234567890,10m:120d:6h:1:true,30m:2y:6h:1:false",
17+
err: false,
18+
out: []Retention{
19+
{
20+
SecondsPerPoint: 1,
21+
NumberOfPoints: 24 * 3600,
22+
ChunkSpan: 60 * 60,
23+
NumChunks: 2,
24+
Ready: 0,
25+
},
26+
{
27+
SecondsPerPoint: 60,
28+
NumberOfPoints: 8 * 24 * 3600 / 60,
29+
ChunkSpan: 4 * 60 * 60,
30+
NumChunks: 2,
31+
Ready: 1234567890,
32+
},
33+
{
34+
SecondsPerPoint: 600,
35+
NumberOfPoints: 120 * 24 * 3600 / 600,
36+
ChunkSpan: 6 * 60 * 60,
37+
NumChunks: 1,
38+
Ready: 0,
39+
},
40+
{
41+
SecondsPerPoint: 30 * 60,
42+
NumberOfPoints: 2 * 365 * 24 * 3600 / (30 * 60),
43+
ChunkSpan: 6 * 60 * 60,
44+
NumChunks: 1,
45+
Ready: math.MaxUint32,
46+
},
47+
},
48+
},
49+
}
50+
for i, c := range cases {
51+
got, err := ParseRetentions(c.in)
52+
if (err != nil) != c.err {
53+
t.Fatalf("case %d: exp error %t but got err %v", i, c.err, err)
54+
}
55+
if c.err {
56+
continue
57+
}
58+
if !reflect.DeepEqual(Retentions(c.out), got) {
59+
t.Fatalf("case %d: exp retentions\n%v\nbut got\n%v", i, c.out, got)
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)