Merge pull request #6773 from codesome/head-test

Refactor TestGCChunkAccess and TestGCSeriesAccess to create chunks by appending samples
This commit is contained in:
Bartlomiej Plotka 2020-02-10 10:53:02 +00:00 committed by GitHub
commit 916e66edf2
1 changed files with 32 additions and 8 deletions

View File

@ -959,10 +959,22 @@ func TestGCChunkAccess(t *testing.T) {
h.initTime(0)
s, _ := h.getOrCreate(1, labels.FromStrings("a", "1"))
s.chunks = []*memChunk{
{minTime: 0, maxTime: 999},
{minTime: 1000, maxTime: 1999},
}
// Appending 2 samples for the first chunk.
ok, chunkCreated := s.append(0, 0)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, chunkCreated, "chunks was not created")
ok, chunkCreated = s.append(999, 999)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, !chunkCreated, "chunks was created")
// A new chunks should be created here as it's beyond the chunk range.
ok, chunkCreated = s.append(1000, 1000)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, chunkCreated, "chunks was not created")
ok, chunkCreated = s.append(1999, 1999)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, !chunkCreated, "chunks was created")
idx := h.indexRange(0, 1500)
var (
@ -999,10 +1011,22 @@ func TestGCSeriesAccess(t *testing.T) {
h.initTime(0)
s, _ := h.getOrCreate(1, labels.FromStrings("a", "1"))
s.chunks = []*memChunk{
{minTime: 0, maxTime: 999},
{minTime: 1000, maxTime: 1999},
}
// Appending 2 samples for the first chunk.
ok, chunkCreated := s.append(0, 0)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, chunkCreated, "chunks was not created")
ok, chunkCreated = s.append(999, 999)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, !chunkCreated, "chunks was created")
// A new chunks should be created here as it's beyond the chunk range.
ok, chunkCreated = s.append(1000, 1000)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, chunkCreated, "chunks was not created")
ok, chunkCreated = s.append(1999, 1999)
testutil.Assert(t, ok, "series append failed")
testutil.Assert(t, !chunkCreated, "chunks was created")
idx := h.indexRange(0, 2000)
var (