mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 17:44:06 -08:00
Add some more tests for MemPostings_Delete
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
This commit is contained in:
parent
4fd2556baa
commit
ada8a6ef10
|
@ -973,6 +973,7 @@ func TestMemPostingsStats(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMemPostings_Delete(t *testing.T) {
|
||||
t.Run("some postings", func(t *testing.T) {
|
||||
p := NewMemPostings()
|
||||
p.Add(1, labels.FromStrings("lbl1", "a"))
|
||||
p.Add(2, labels.FromStrings("lbl1", "b"))
|
||||
|
@ -1004,6 +1005,37 @@ func TestMemPostings_Delete(t *testing.T) {
|
|||
expanded, err = ExpandPostings(deleted)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, expanded, "expected empty postings, got %v", expanded)
|
||||
})
|
||||
|
||||
t.Run("all postings", func(t *testing.T) {
|
||||
p := NewMemPostings()
|
||||
p.Add(1, labels.FromStrings("lbl1", "a"))
|
||||
p.Add(2, labels.FromStrings("lbl1", "b"))
|
||||
p.Add(3, labels.FromStrings("lbl2", "a"))
|
||||
|
||||
deletedRefs := map[storage.SeriesRef]struct{}{1: {}, 2: {}, 3: {}}
|
||||
affectedLabels := map[labels.Label]struct{}{
|
||||
{Name: "lbl1", Value: "a"}: {},
|
||||
{Name: "lbl1", Value: "b"}: {},
|
||||
{Name: "lbl1", Value: "c"}: {},
|
||||
}
|
||||
p.Delete(deletedRefs, affectedLabels)
|
||||
after := p.Get(allPostingsKey.Name, allPostingsKey.Value)
|
||||
expanded, err := ExpandPostings(after)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, expanded)
|
||||
})
|
||||
|
||||
t.Run("nothing on empty mempostings", func(t *testing.T) {
|
||||
p := NewMemPostings()
|
||||
deletedRefs := map[storage.SeriesRef]struct{}{}
|
||||
affectedLabels := map[labels.Label]struct{}{}
|
||||
p.Delete(deletedRefs, affectedLabels)
|
||||
after := p.Get(allPostingsKey.Name, allPostingsKey.Value)
|
||||
expanded, err := ExpandPostings(after)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, expanded)
|
||||
})
|
||||
}
|
||||
|
||||
// BenchmarkMemPostings_Delete is quite heavy, so consider running it with
|
||||
|
|
Loading…
Reference in a new issue