mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/protoparser/prometheus: sort rows before comparing them in TestParseStream, since the order for callback calls is non-deterministic
This commit is contained in:
parent
7cde336b33
commit
19c0b6f3ef
1 changed files with 15 additions and 5 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"compress/gzip"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -39,6 +40,7 @@ func TestParseStream(t *testing.T) {
|
|||
case <-time.After(time.Second):
|
||||
t.Fatalf("timeout")
|
||||
}
|
||||
sortRows(result)
|
||||
if !reflect.DeepEqual(result, rowsExpected) {
|
||||
t.Fatalf("unexpected rows parsed; got\n%v\nwant\n%v", result, rowsExpected)
|
||||
}
|
||||
|
@ -71,6 +73,7 @@ func TestParseStream(t *testing.T) {
|
|||
case <-time.After(time.Second):
|
||||
t.Fatalf("timeout on compressed stream")
|
||||
}
|
||||
sortRows(result)
|
||||
if !reflect.DeepEqual(result, rowsExpected) {
|
||||
t.Fatalf("unexpected compressed rows parsed; got\n%v\nwant\n%v", result, rowsExpected)
|
||||
}
|
||||
|
@ -82,6 +85,11 @@ func TestParseStream(t *testing.T) {
|
|||
Timestamp: 456,
|
||||
}})
|
||||
f(`foo{bar="baz"} 1 2`+"\n"+`aaa{} 3 4`, []Row{
|
||||
{
|
||||
Metric: "aaa",
|
||||
Value: 3,
|
||||
Timestamp: 4,
|
||||
},
|
||||
{
|
||||
Metric: "foo",
|
||||
Tags: []Tag{{
|
||||
|
@ -91,11 +99,6 @@ func TestParseStream(t *testing.T) {
|
|||
Value: 1,
|
||||
Timestamp: 2,
|
||||
},
|
||||
{
|
||||
Metric: "aaa",
|
||||
Value: 3,
|
||||
Timestamp: 4,
|
||||
},
|
||||
})
|
||||
f("foo 23", []Row{{
|
||||
Metric: "foo",
|
||||
|
@ -104,6 +107,13 @@ func TestParseStream(t *testing.T) {
|
|||
}})
|
||||
}
|
||||
|
||||
func sortRows(rows []Row) {
|
||||
sort.Slice(rows, func(i, j int) bool {
|
||||
a, b := rows[i], rows[j]
|
||||
return a.Metric < b.Metric
|
||||
})
|
||||
}
|
||||
|
||||
func appendRowCopies(dst, src []Row) []Row {
|
||||
for _, r := range src {
|
||||
// Make a copy of r, since r may contain garbage after returning from the callback to ParseStream.
|
||||
|
|
Loading…
Reference in a new issue