TestHeadDetectsDuplicateSampleAtSizeLimit tests a regression where a duplicate sample is appended to the head, right when the head chunk is at the size limit. The test adds all samples as duplicate, thus expecting that the result has exactly half of the samples.
(t *testing.T)
| 6895 | // The test adds all samples as duplicate, thus expecting that the result has |
| 6896 | // exactly half of the samples. |
| 6897 | func TestHeadDetectsDuplicateSampleAtSizeLimit(t *testing.T) { |
| 6898 | numSamples := 1000 |
| 6899 | baseTS := int64(1695209650) |
| 6900 | |
| 6901 | h, _ := newTestHead(t, DefaultBlockDuration, compression.None, false) |
| 6902 | |
| 6903 | a := h.Appender(context.Background()) |
| 6904 | var err error |
| 6905 | vals := []float64{math.MaxFloat64, 0x00} // Use the worst case scenario for the XOR encoding. Otherwise we hit the sample limit before the size limit. |
| 6906 | for i := range numSamples { |
| 6907 | ts := baseTS + int64(i/2)*10000 |
| 6908 | a.Append(0, labels.FromStrings("foo", "bar"), ts, vals[(i/2)%len(vals)]) |
| 6909 | err = a.Commit() |
| 6910 | require.NoError(t, err) |
| 6911 | a = h.Appender(context.Background()) |
| 6912 | } |
| 6913 | |
| 6914 | indexReader, err := h.Index() |
| 6915 | require.NoError(t, err) |
| 6916 | |
| 6917 | var ( |
| 6918 | chunks []chunks.Meta |
| 6919 | builder labels.ScratchBuilder |
| 6920 | ) |
| 6921 | require.NoError(t, indexReader.Series(1, &builder, &chunks)) |
| 6922 | |
| 6923 | chunkReader, err := h.Chunks() |
| 6924 | require.NoError(t, err) |
| 6925 | |
| 6926 | storedSampleCount := 0 |
| 6927 | for _, chunkMeta := range chunks { |
| 6928 | chunk, iterable, err := chunkReader.ChunkOrIterable(chunkMeta) |
| 6929 | require.NoError(t, err) |
| 6930 | require.Nil(t, iterable) |
| 6931 | storedSampleCount += chunk.NumSamples() |
| 6932 | } |
| 6933 | |
| 6934 | require.Equal(t, numSamples/2, storedSampleCount) |
| 6935 | } |
| 6936 | |
| 6937 | func TestWALSampleAndExemplarOrder(t *testing.T) { |
| 6938 | lbls := labels.FromStrings("foo", "bar") |
nothing calls this directly
no test coverage detected
searching dependent graphs…