Skip to content

Commit

Permalink
Change test to support unordered results
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontj committed Sep 21, 2021
1 parent 6f2e4d7 commit 6dc5069
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion promql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ package promql
import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"reflect"
"sort"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -241,10 +244,13 @@ type hintRecordingQuerier struct {
storage.Querier

h *noopHintRecordingQueryable
l sync.Mutex
}

func (h *hintRecordingQuerier) Select(sortSeries bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
h.l.Lock()
h.h.hints = append(h.h.hints, hints)
h.l.Unlock()
return h.Querier.Select(sortSeries, hints, matchers...)
}

Expand Down Expand Up @@ -557,7 +563,25 @@ func TestSelectHintsSetCorrectly(t *testing.T) {
res := query.Exec(context.Background())
require.NoError(t, res.Err)

require.Equal(t, tc.expected, hintsRecorder.hints)
require.Equal(t, len(tc.expected), len(hintsRecorder.hints))
for _, item := range tc.expected {
found := false
for _, other := range hintsRecorder.hints {
if reflect.DeepEqual(*item, *other) {
found = true
break
}
}
if !found {
for i, e := range tc.expected {
fmt.Println(i, *e)
}
for i, e := range hintsRecorder.hints {
fmt.Println(i, *e)
}
}
require.Equal(t, found, true)
}
})

}
Expand Down

0 comments on commit 6dc5069

Please sign in to comment.