Fix tiered storage test to trigger iterator rewinding case.

This commit is contained in:
Julius Volz 2013-03-12 10:27:27 -07:00 committed by Matt T. Proud
parent 894ecfe161
commit 2f06b8bea6

View file

@ -23,10 +23,8 @@ import (
"time" "time"
) )
func sampleIncrement(from, to time.Time, interval time.Duration, m model.Metric) (v []model.Sample) { func buildSamples(from, to time.Time, interval time.Duration, m model.Metric) (v []model.Sample) {
var ( i := model.SampleValue(0)
i model.SampleValue = 0
)
for from.Before(to) { for from.Before(to) {
v = append(v, model.Sample{ v = append(v, model.Sample{
@ -36,6 +34,7 @@ func sampleIncrement(from, to time.Time, interval time.Duration, m model.Metric)
}) })
from = from.Add(interval) from = from.Add(interval)
i++
} }
return return
@ -54,7 +53,7 @@ func testMakeView(t test.Tester) {
alongRange [][]model.SamplePair alongRange [][]model.SamplePair
} }
var ( var (
instant = time.Date(1984, 3, 30, 0, 0, 0, 0, time.UTC) instant = time.Date(1984, 3, 30, 0, 0, 0, 0, time.Local)
metric = model.Metric{"name": "request_count"} metric = model.Metric{"name": "request_count"}
fingerprint = model.NewFingerprintFromMetric(metric) fingerprint = model.NewFingerprintFromMetric(metric)
scenarios = []struct { scenarios = []struct {
@ -243,37 +242,37 @@ func testMakeView(t test.Tester) {
}, },
}, },
}, },
// { {
// data: sampleIncrement(instant, instant.Add(14*24*time.Hour), time.Second, metric), data: buildSamples(instant, instant.Add(400*time.Second), time.Second, metric),
// in: in{ in: in{
// atTime: []getValuesAtTimeOp{ atTime: []getValuesAtTimeOp{
// { {
// time: instant.Add(time.Second * 3), time: instant.Add(time.Second * 100),
// }, },
// }, },
// }, },
// out: out{ out: out{
// atTime: [][]model.SamplePair{ atTime: [][]model.SamplePair{
// { {
// { {
// Timestamp: instant.Add(time.Second * 2), Timestamp: instant.Add(time.Second * 100),
// Value: 1, Value: 100,
// }, },
// { {
// Timestamp: instant.Add(time.Second * 4), Timestamp: instant.Add(time.Second * 100),
// Value: 2, Value: 101,
// }, },
// }, },
// }, },
// }, },
// }, },
} }
) )
for i, scenario := range scenarios { for i, scenario := range scenarios {
var ( var (
temporary, _ = ioutil.TempDir("", "test_make_view") temporary, _ = ioutil.TempDir("", "test_make_view")
tiered = NewTieredStorage(5000000, 250, 1000, 5*time.Second, 15*time.Second, 0*time.Second, temporary) tiered = NewTieredStorage(5000000, 2500, 1000, 5*time.Second, 15*time.Second, 0*time.Second, temporary)
) )
if tiered == nil { if tiered == nil {
@ -327,10 +326,10 @@ func testMakeView(t test.Tester) {
for k, value := range scenario.out.atTime[j] { for k, value := range scenario.out.atTime[j] {
if value.Value != actual[k].Value { if value.Value != actual[k].Value {
t.Fatalf("%d.%d.%d expected %d value, got %d", i, j, k, value.Value, actual[j].Value) t.Fatalf("%d.%d.%d expected %v value, got %v", i, j, k, value.Value, actual[k].Value)
} }
if !value.Timestamp.Equal(actual[k].Timestamp) { if !value.Timestamp.Equal(actual[k].Timestamp) {
t.Fatalf("%d.%d.%d expected %s timestamp, got %s", i, j, k, value.Timestamp, actual[j].Timestamp) t.Fatalf("%d.%d.%d expected %s timestamp, got %s", i, j, k, value.Timestamp, actual[k].Timestamp)
} }
} }
} }