From 0279b9d39e0a348aca8740a1e2bbbaac9b0a60e1 Mon Sep 17 00:00:00 2001 From: alexandru topliceanu Date: Mon, 10 Jan 2022 12:42:42 +0000 Subject: [PATCH 1/2] add CI pipeline step to run the race detector against the tests --- .github/workflows/relay.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/relay.yml b/.github/workflows/relay.yml index b6592aad3..f5295032d 100644 --- a/.github/workflows/relay.yml +++ b/.github/workflows/relay.yml @@ -19,6 +19,8 @@ jobs: run: go build -v ./pkg/... - name: Test run: go test ./pkg/... -v + - name: Test with the race detector enabled + run: go test ./pkg/... -v -race -count=10 lint: runs-on: ubuntu-latest From 80d67f917e8586da1e3843e9fa9da19d565a4d76 Mon Sep 17 00:00:00 2001 From: alexandru topliceanu Date: Mon, 10 Jan 2022 13:00:50 +0000 Subject: [PATCH 2/2] fix data race in the multi-feed-monitor test --- pkg/monitoring/multi_feed_monitor_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/monitoring/multi_feed_monitor_test.go b/pkg/monitoring/multi_feed_monitor_test.go index 96ad9633c..410710b74 100644 --- a/pkg/monitoring/multi_feed_monitor_test.go +++ b/pkg/monitoring/multi_feed_monitor_test.go @@ -3,6 +3,7 @@ package monitoring import ( "context" "sync" + "sync/atomic" "testing" "time" @@ -121,7 +122,7 @@ func TestMultiFeedMonitorForPerformance(t *testing.T) { ) go monitor.Start(ctx, wg) - trCount, stCount := 0, 0 + var trCount, stCount int64 = 0, 0 messages := []producerMessage{} wg.Add(1) @@ -133,9 +134,9 @@ func TestMultiFeedMonitorForPerformance(t *testing.T) { require.NoError(t, err) select { case transmissionReader.readCh <- generateTransmissionEnvelope(): - trCount += 1 + _ = atomic.AddInt64(&trCount, 1) case stateReader.readCh <- StateEnvelope{newState, 100}: - stCount += 1 + _ = atomic.AddInt64(&stCount, 1) case <-ctx.Done(): break LOOP } @@ -156,7 +157,7 @@ func TestMultiFeedMonitorForPerformance(t *testing.T) { }() wg.Wait() - require.Equal(t, 10, trCount, "should only be able to do initial read of the latest transmission") - require.Equal(t, 10, stCount, "should only be able to do initial read of the state account") + require.Equal(t, int64(10), trCount, "should only be able to do initial read of the latest transmission") + require.Equal(t, int64(10), stCount, "should only be able to do initial read of the state account") require.Equal(t, 30, len(messages)) }