Skip to content

Commit

Permalink
use mutexes in tests to prevent race condition failures
Browse files Browse the repository at this point in the history
  • Loading branch information
jmurret committed Aug 30, 2022
1 parent 7ebe704 commit 12ff49e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 1 addition & 6 deletions memberlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,8 @@ func TestCreate_checkBroadcastQueueMetrics(t *testing.T) {

time.Sleep(3 * time.Second)

intv := getIntervalMetrics(t, sink)
sampleName := "consul.usage.test.memberlist.queue.broadcasts"
actualSample := intv.Samples[sampleName]

if actualSample.Count == 0 {
t.Fatalf("%s sample not taken", sampleName)
}
verifySampleExists(t, sampleName, sink)
}

func TestCreate_keyringOnly(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,18 @@ func getIntervalMetrics(t *testing.T, sink *metrics.InmemSink) *metrics.Interval

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

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

0 comments on commit 12ff49e

Please sign in to comment.