Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
pmmukh committed Oct 13, 2021
1 parent d6aeafc commit 3c47f12
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vault/core_metrics_test.go
Expand Up @@ -2,6 +2,7 @@ package vault

import (
"errors"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -323,6 +324,15 @@ func TestCoreMetrics_EntityGauges(t *testing.T) {
t.Errorf("Alias count %v, expected %v", glv[0].Value, 1.0)
}

// Sort both metrics.Label slices by Name, causing the Label
// with Name auth_method to be first in both arrays
sort.Slice(glv[0].Labels, func(i, j int) bool { return glv[0].Labels[i].Name < glv[0].Labels[j].Name })
sort.Slice(glv[1].Labels, func(i, j int) bool { return glv[1].Labels[i].Name < glv[1].Labels[j].Name })

// Sort the GaugeLabelValues slice by the Value of the first metric,
// in this case auth_method, in each metrics.Label slice
sort.Slice(glv, func(i, j int) bool { return glv[i].Labels[0].Value < glv[j].Labels[0].Value })

metricLabelsMatch(t, glv[0].Labels,
map[string]string{
"namespace": "root",
Expand Down

0 comments on commit 3c47f12

Please sign in to comment.