mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Change test to support unordered results
This commit is contained in:
parent
10e204680f
commit
289c7fdb60
|
@ -18,6 +18,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -295,10 +296,13 @@ type hintRecordingQuerier struct {
|
||||||
storage.Querier
|
storage.Querier
|
||||||
|
|
||||||
h *noopHintRecordingQueryable
|
h *noopHintRecordingQueryable
|
||||||
|
l sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *hintRecordingQuerier) Select(ctx context.Context, sortSeries bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
|
func (h *hintRecordingQuerier) Select(ctx context.Context, sortSeries bool, hints *storage.SelectHints, matchers ...*labels.Matcher) storage.SeriesSet {
|
||||||
|
h.l.Lock()
|
||||||
h.h.hints = append(h.h.hints, hints)
|
h.h.hints = append(h.h.hints, hints)
|
||||||
|
h.l.Unlock()
|
||||||
return h.Querier.Select(ctx, sortSeries, hints, matchers...)
|
return h.Querier.Select(ctx, sortSeries, hints, matchers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +617,25 @@ func TestSelectHintsSetCorrectly(t *testing.T) {
|
||||||
res := query.Exec(context.Background())
|
res := query.Exec(context.Background())
|
||||||
require.NoError(t, res.Err)
|
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)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,8 +386,7 @@ func (f inspector) Visit(node Node, path []Node) (Visitor, error) {
|
||||||
// f(node, path); node must not be nil. If f returns a nil error, Inspect invokes f
|
// f(node, path); node must not be nil. If f returns a nil error, Inspect invokes f
|
||||||
// for all the non-nil children of node, recursively.
|
// for all the non-nil children of node, recursively.
|
||||||
func Inspect(ctx context.Context, s *EvalStmt, f inspector, nr NodeReplacer) (Node, error) {
|
func Inspect(ctx context.Context, s *EvalStmt, f inspector, nr NodeReplacer) (Node, error) {
|
||||||
//nolint: errcheck
|
return Walk(ctx, inspector(f), s, s.Expr, nil, nr) //nolint: errcheck
|
||||||
return Walk(ctx, inspector(f), s, s.Expr, nil, nr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetChild(node Node, i int, child Node) {
|
func SetChild(node Node, i int, child Node) {
|
||||||
|
|
Loading…
Reference in a new issue