diff --git a/lib/protoparser/prometheus/streamparser_test.go b/lib/protoparser/prometheus/streamparser_test.go index 09feba6e8..6d60cb5ea 100644 --- a/lib/protoparser/prometheus/streamparser_test.go +++ b/lib/protoparser/prometheus/streamparser_test.go @@ -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.