chore: Simplify TestHeadAppender_AppendCTZeroSample (#14812)

Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
This commit is contained in:
Arthur Silva Sens 2024-09-02 17:30:37 -03:00 committed by GitHub
parent 2cfc7b244a
commit 442f24e099
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 36 additions and 45 deletions

View File

@ -33,7 +33,6 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/atomic" "go.uber.org/atomic"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
@ -5945,16 +5944,16 @@ func TestHeadAppender_AppendCTZeroSample(t *testing.T) {
for _, tc := range []struct { for _, tc := range []struct {
name string name string
appendableSamples []appendableSamples appendableSamples []appendableSamples
expectedSamples []model.Sample expectedSamples []chunks.Sample
}{ }{
{ {
name: "In order ct+normal sample", name: "In order ct+normal sample",
appendableSamples: []appendableSamples{ appendableSamples: []appendableSamples{
{ts: 100, val: 10, ct: 1}, {ts: 100, val: 10, ct: 1},
}, },
expectedSamples: []model.Sample{ expectedSamples: []chunks.Sample{
{Timestamp: 1, Value: 0}, sample{t: 1, f: 0},
{Timestamp: 100, Value: 10}, sample{t: 100, f: 10},
}, },
}, },
{ {
@ -5963,10 +5962,10 @@ func TestHeadAppender_AppendCTZeroSample(t *testing.T) {
{ts: 100, val: 10, ct: 1}, {ts: 100, val: 10, ct: 1},
{ts: 101, val: 10, ct: 1}, {ts: 101, val: 10, ct: 1},
}, },
expectedSamples: []model.Sample{ expectedSamples: []chunks.Sample{
{Timestamp: 1, Value: 0}, sample{t: 1, f: 0},
{Timestamp: 100, Value: 10}, sample{t: 100, f: 10},
{Timestamp: 101, Value: 10}, sample{t: 101, f: 10},
}, },
}, },
{ {
@ -5975,11 +5974,11 @@ func TestHeadAppender_AppendCTZeroSample(t *testing.T) {
{ts: 100, val: 10, ct: 1}, {ts: 100, val: 10, ct: 1},
{ts: 102, val: 10, ct: 101}, {ts: 102, val: 10, ct: 101},
}, },
expectedSamples: []model.Sample{ expectedSamples: []chunks.Sample{
{Timestamp: 1, Value: 0}, sample{t: 1, f: 0},
{Timestamp: 100, Value: 10}, sample{t: 100, f: 10},
{Timestamp: 101, Value: 0}, sample{t: 101, f: 0},
{Timestamp: 102, Value: 10}, sample{t: 102, f: 10},
}, },
}, },
{ {
@ -5988,13 +5987,14 @@ func TestHeadAppender_AppendCTZeroSample(t *testing.T) {
{ts: 100, val: 10, ct: 1}, {ts: 100, val: 10, ct: 1},
{ts: 101, val: 10, ct: 100}, {ts: 101, val: 10, ct: 100},
}, },
expectedSamples: []model.Sample{ expectedSamples: []chunks.Sample{
{Timestamp: 1, Value: 0}, sample{t: 1, f: 0},
{Timestamp: 100, Value: 10}, sample{t: 100, f: 10},
{Timestamp: 101, Value: 10}, sample{t: 101, f: 10},
}, },
}, },
} { } {
t.Run(tc.name, func(t *testing.T) {
h, _ := newTestHead(t, DefaultBlockDuration, wlog.CompressionNone, false) h, _ := newTestHead(t, DefaultBlockDuration, wlog.CompressionNone, false)
defer func() { defer func() {
require.NoError(t, h.Close()) require.NoError(t, h.Close())
@ -6011,18 +6011,9 @@ func TestHeadAppender_AppendCTZeroSample(t *testing.T) {
q, err := NewBlockQuerier(h, math.MinInt64, math.MaxInt64) q, err := NewBlockQuerier(h, math.MinInt64, math.MaxInt64)
require.NoError(t, err) require.NoError(t, err)
ss := q.Select(context.Background(), false, nil, labels.MustNewMatcher(labels.MatchEqual, "foo", "bar")) result := query(t, q, labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"))
require.True(t, ss.Next()) require.Equal(t, tc.expectedSamples, result[`{foo="bar"}`])
s := ss.At() })
require.False(t, ss.Next())
it := s.Iterator(nil)
for _, sample := range tc.expectedSamples {
require.Equal(t, chunkenc.ValFloat, it.Next())
timestamp, value := it.At()
require.Equal(t, sample.Timestamp, model.Time(timestamp))
require.Equal(t, sample.Value, model.SampleValue(value))
}
require.Equal(t, chunkenc.ValNone, it.Next())
} }
} }