From 7ada179aef67ccb3c5bd8b8e3937bbeb671aec5f Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Tue, 15 Sep 2020 10:43:46 +0100 Subject: [PATCH] enable -race on go test (#7305) Introduce 'norace' build tag that is used to filter out test files containing test cases or test suites that, if run with the -race flag on would cause race conditions. Supersede #7300. --- .github/workflows/test.yml | 89 ++++++++++++++++++++++-- Makefile | 8 +-- client/grpc_query_test.go | 2 + server/grpc/server_test.go | 2 + testutil/network/network_test.go | 2 + x/auth/client/cli/cli_test.go | 2 + x/auth/client/rest/rest_test.go | 2 + x/auth/vesting/client/cli/cli_test.go | 2 + x/bank/client/rest/grpc_query_test.go | 2 + x/bank/client/rest/query_test.go | 2 + x/bank/client/rest/tx_test.go | 2 + x/bank/keeper/grpc_query_test.go | 2 + x/crisis/client/cli/cli_test.go | 2 + x/distribution/client/cli/cli_test.go | 2 + x/gov/client/cli/cli_test.go | 2 + x/mint/client/cli/cli_test.go | 2 + x/mint/client/rest/grpc_query_test.go | 2 + x/params/client/cli/cli_test.go | 2 + x/slashing/client/cli/cli_test.go | 2 + x/staking/client/cli/cli_test.go | 2 + x/staking/client/rest/grpc_query_test.go | 2 + 21 files changed, 127 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 96311595e2..ee4ba111ee 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,7 @@ jobs: - name: Run cosmovisor tests run: cd cosmovisor; make if: "env.GIT_DIFF != ''" + split-test-files: runs-on: ubuntu-latest steps: @@ -76,7 +77,7 @@ jobs: if: "env.GIT_DIFF != ''" - name: test & coverage report creation run: | - cat xaa.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' + cat xaa.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock' if: "env.GIT_DIFF != ''" - name: filter out DONTCOVER run: | @@ -113,7 +114,7 @@ jobs: if: "env.GIT_DIFF != ''" - name: test & coverage report creation run: | - cat xab.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' + cat xab.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock' if: "env.GIT_DIFF != ''" - name: filter out DONTCOVER run: | @@ -150,7 +151,7 @@ jobs: if: "env.GIT_DIFF != ''" - name: test & coverage report creation run: | - cat xac.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' + cat xac.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock' if: "env.GIT_DIFF != ''" - name: filter out DONTCOVER run: | @@ -187,7 +188,7 @@ jobs: if: "env.GIT_DIFF != ''" - name: test & coverage report creation run: | - cat xad.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' + cat xad.txt | xargs go test -mod=readonly -timeout 15m -coverprofile=coverage.txt -covermode=atomic -tags='norace ledger test_ledger_mock' if: "env.GIT_DIFF != ''" - name: filter out DONTCOVER run: | @@ -205,6 +206,86 @@ jobs: file: ./coverage.txt if: "env.GIT_DIFF != ''" + test-race-1: + runs-on: ubuntu-latest + needs: split-test-files + timeout-minutes: 15 + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v3 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - uses: actions/download-artifact@v2 + with: + name: "${{ github.sha }}-aa" + if: "env.GIT_DIFF != ''" + - name: Run tests with race detector + run: cat xaa.txt | xargs go test -mod=readonly -timeout 15m -race -tags='cgo ledger test_ledger_mock' + + test-race-2: + runs-on: ubuntu-latest + needs: split-test-files + timeout-minutes: 15 + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v3 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - uses: actions/download-artifact@v2 + with: + name: "${{ github.sha }}-ab" + if: "env.GIT_DIFF != ''" + - name: Run tests with race detector + run: cat xab.txt | xargs go test -mod=readonly -timeout 15m -race -tags='cgo ledger test_ledger_mock' + + test-race-3: + runs-on: ubuntu-latest + needs: split-test-files + timeout-minutes: 15 + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v3 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - uses: actions/download-artifact@v2 + with: + name: "${{ github.sha }}-ac" + if: "env.GIT_DIFF != ''" + - name: Run tests with race detector + run: cat xac.txt | xargs go test -mod=readonly -timeout 15m -race -tags='cgo ledger test_ledger_mock' + + test-race-4: + runs-on: ubuntu-latest + needs: split-test-files + timeout-minutes: 15 + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v3 + id: git_diff + with: + SUFFIX_FILTER: | + .go + .mod + .sum + - uses: actions/download-artifact@v2 + with: + name: "${{ github.sha }}-ad" + if: "env.GIT_DIFF != ''" + - name: Run tests with race detector + run: cat xad.txt | xargs go test -mod=readonly -timeout 15m -race -tags='cgo ledger test_ledger_mock' + liveness-test: runs-on: ubuntu-latest timeout-minutes: 10 diff --git a/Makefile b/Makefile index cdd8efb19a..60b2aee1fc 100644 --- a/Makefile +++ b/Makefile @@ -211,10 +211,10 @@ TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test- # a new rule, customise ARGS or TEST_PACKAGES ad libitum, and # append the new rule to the TEST_TARGETS list. -test-unit: ARGS=-tags='cgo ledger test_ledger_mock' -test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino' -test-ledger: ARGS=-tags='cgo ledger' -test-ledger-mock: ARGS=-tags='ledger test_ledger_mock' +test-unit: ARGS=-tags='cgo ledger test_ledger_mock norace' +test-unit-amino: ARGS=-tags='ledger test_ledger_mock test_amino norace' +test-ledger: ARGS=-tags='cgo ledger norace' +test-ledger-mock: ARGS=-tags='ledger test_ledger_mock norace' test-race: ARGS=-race -tags='cgo ledger test_ledger_mock' test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION) diff --git a/client/grpc_query_test.go b/client/grpc_query_test.go index 438840f521..7dd851a4d5 100644 --- a/client/grpc_query_test.go +++ b/client/grpc_query_test.go @@ -1,3 +1,5 @@ +// +build norace + package client_test import ( diff --git a/server/grpc/server_test.go b/server/grpc/server_test.go index 5af368494c..953aa825c5 100644 --- a/server/grpc/server_test.go +++ b/server/grpc/server_test.go @@ -1,3 +1,5 @@ +// +build norace + package grpc_test import ( diff --git a/testutil/network/network_test.go b/testutil/network/network_test.go index e7b248e31a..3e45309f2f 100644 --- a/testutil/network/network_test.go +++ b/testutil/network/network_test.go @@ -1,3 +1,5 @@ +// +build norace + package network_test import ( diff --git a/x/auth/client/cli/cli_test.go b/x/auth/client/cli/cli_test.go index 57a9bc6f1c..0ab22d3f22 100644 --- a/x/auth/client/cli/cli_test.go +++ b/x/auth/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/auth/client/rest/rest_test.go b/x/auth/client/rest/rest_test.go index 6979801501..a25a34e596 100644 --- a/x/auth/client/rest/rest_test.go +++ b/x/auth/client/rest/rest_test.go @@ -1,3 +1,5 @@ +// +build norace + package rest_test import ( diff --git a/x/auth/vesting/client/cli/cli_test.go b/x/auth/vesting/client/cli/cli_test.go index ce2e13e8f2..ebd417a62b 100644 --- a/x/auth/vesting/client/cli/cli_test.go +++ b/x/auth/vesting/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/bank/client/rest/grpc_query_test.go b/x/bank/client/rest/grpc_query_test.go index 589adca53f..2f2cf2e264 100644 --- a/x/bank/client/rest/grpc_query_test.go +++ b/x/bank/client/rest/grpc_query_test.go @@ -1,3 +1,5 @@ +// +build norace + package rest_test import ( diff --git a/x/bank/client/rest/query_test.go b/x/bank/client/rest/query_test.go index 3705606a7d..bbd803ba75 100644 --- a/x/bank/client/rest/query_test.go +++ b/x/bank/client/rest/query_test.go @@ -1,3 +1,5 @@ +// +build norace + package rest_test import ( diff --git a/x/bank/client/rest/tx_test.go b/x/bank/client/rest/tx_test.go index 1fc73916a6..118816c793 100644 --- a/x/bank/client/rest/tx_test.go +++ b/x/bank/client/rest/tx_test.go @@ -1,3 +1,5 @@ +// +build norace + package rest_test import ( diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 09effcf5bd..9e34d08e8a 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -1,3 +1,5 @@ +// +build norace + package keeper_test import ( diff --git a/x/crisis/client/cli/cli_test.go b/x/crisis/client/cli/cli_test.go index ef135b2de4..92b4396149 100644 --- a/x/crisis/client/cli/cli_test.go +++ b/x/crisis/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/distribution/client/cli/cli_test.go b/x/distribution/client/cli/cli_test.go index 0b6fea8c67..35b212a81e 100644 --- a/x/distribution/client/cli/cli_test.go +++ b/x/distribution/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/gov/client/cli/cli_test.go b/x/gov/client/cli/cli_test.go index ae60494ff0..47bc19be97 100644 --- a/x/gov/client/cli/cli_test.go +++ b/x/gov/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/mint/client/cli/cli_test.go b/x/mint/client/cli/cli_test.go index ffe1fc3528..6425f369a9 100644 --- a/x/mint/client/cli/cli_test.go +++ b/x/mint/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/mint/client/rest/grpc_query_test.go b/x/mint/client/rest/grpc_query_test.go index f1d2adbec7..b2024e7d57 100644 --- a/x/mint/client/rest/grpc_query_test.go +++ b/x/mint/client/rest/grpc_query_test.go @@ -1,3 +1,5 @@ +// +build norace + package rest_test import ( diff --git a/x/params/client/cli/cli_test.go b/x/params/client/cli/cli_test.go index 4db43c9e9e..6254a45eaf 100644 --- a/x/params/client/cli/cli_test.go +++ b/x/params/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/slashing/client/cli/cli_test.go b/x/slashing/client/cli/cli_test.go index e925e64336..41fac414c7 100644 --- a/x/slashing/client/cli/cli_test.go +++ b/x/slashing/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/staking/client/cli/cli_test.go b/x/staking/client/cli/cli_test.go index 38e89f6ec7..88945a10fb 100644 --- a/x/staking/client/cli/cli_test.go +++ b/x/staking/client/cli/cli_test.go @@ -1,3 +1,5 @@ +// +build norace + package cli_test import ( diff --git a/x/staking/client/rest/grpc_query_test.go b/x/staking/client/rest/grpc_query_test.go index 6a7fd29014..d2a45aa18f 100644 --- a/x/staking/client/rest/grpc_query_test.go +++ b/x/staking/client/rest/grpc_query_test.go @@ -1,3 +1,5 @@ +// +build norace + package rest_test import (