Skip to content

Commit

Permalink
change verify gauge and sample test function to only take in a string
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Aug 30, 2022
1 parent f4dc332 commit 9400939
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion memberlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestCreate_checkBroadcastQueueMetrics(t *testing.T) {
time.Sleep(3 * time.Second)

sampleName := "consul.usage.test.memberlist.queue.broadcasts"
verifySamplesExists(t, []string{sampleName}, sink)
verifySampleExists(t, sampleName, sink)
}

func TestCreate_keyringOnly(t *testing.T) {
Expand Down
28 changes: 12 additions & 16 deletions state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2274,12 +2274,11 @@ func TestMemberlist_PushPull(t *testing.T) {
}

instancesMetricName := "consul.usage.test.memberlist.node.instances"
verifyGaugesExists(t, []string{"consul.usage.test.memberlist.size.local",
fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateAlive),
fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateDead),
fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateLeft),
fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateSuspect)},
sink)
verifyGaugeExists(t, "consul.usage.test.memberlist.size.local", sink)
verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateAlive), sink)
verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateDead), sink)
verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateLeft), sink)
verifyGaugeExists(t, fmt.Sprintf("%s;node_state=%s", instancesMetricName, nodeStateSuspect), sink)
})
}

Expand Down Expand Up @@ -2423,24 +2422,21 @@ func getIntervalMetrics(t *testing.T, sink *metrics.InmemSink) *metrics.Interval
return intv
}

func verifyGaugesExists(t *testing.T, names []string, sink *metrics.InmemSink) {
func verifyGaugeExists(t *testing.T, name string, sink *metrics.InmemSink) {
interval := getIntervalMetrics(t, sink)
interval.RLock()
defer interval.RUnlock()
for _, name := range names {
if _, ok := interval.Gauges[name]; !ok {
t.Fatalf("%s gauge not emmited", name)
}
if _, ok := interval.Gauges[name]; !ok {
t.Fatalf("%s gauge not emmited", name)
}
}

func verifySamplesExists(t *testing.T, names []string, sink *metrics.InmemSink) {
func verifySampleExists(t *testing.T, name string, sink *metrics.InmemSink) {
interval := getIntervalMetrics(t, sink)
interval.RLock()
defer interval.RUnlock()
for _, name := range names {
if _, ok := interval.Samples[name]; !ok {
t.Fatalf("%s sample not emmited", name)
}

if _, ok := interval.Samples[name]; !ok {
t.Fatalf("%s sample not emmited", name)
}
}

0 comments on commit 9400939

Please sign in to comment.