Skip to content

Commit

Permalink
tests: Fix t.Parallel() errors in cmd package (#4991)
Browse files Browse the repository at this point in the history
Co-authored-by: algochoi <[email protected]>
  • Loading branch information
michaeldiamant and algochoi authored Mar 7, 2023
1 parent 843637c commit 4bbedc0
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 44 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ issues:
- path: ^catchup.*_test\.go
linters:
- paralleltest
- path: ^cmd.*_test\.go
linters:
- paralleltest
- path: ^config.*_test\.go
linters:
- paralleltest
Expand Down
3 changes: 3 additions & 0 deletions cmd/algocfg/getCommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

func TestPrint(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

testcases := []struct {
Input interface{}
Expand Down Expand Up @@ -55,7 +56,9 @@ func TestPrint(t *testing.T) {
},
}
for i, tc := range testcases {
tc := tc
t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) {
t.Parallel()
ret, err := serializeObjectProperty(tc, "Input")
assert.NoError(t, err)
assert.Equal(t, tc.expected, ret)
Expand Down
4 changes: 4 additions & 0 deletions cmd/algofix/deadlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ func main() {

func TestDeadlockRewrite(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

// nolint:paralleltest // Subtests modify shared resources.
t.Run("simple", func(t *testing.T) { testDeadlock(t, deadlockSimpleSrc, deadlockSimpleDest) })
// nolint:paralleltest // Subtests modify shared resources.
t.Run("onoff", func(t *testing.T) { testDeadlock(t, deadlockTestSrc, deadlockTestFin) })
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/algofix/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustB

func TestRewrite(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

for _, tt := range testCases {
// Apply fix: should get tt.Out.
out, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)
Expand Down
10 changes: 10 additions & 0 deletions cmd/algoh/blockWatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func bw(client Client) *blockWatcher {
// Then blockIfStalled will block until the next block is reported
func TestBlockIfStalled(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

client := mockClient{
error: []error{nil, nil, nil},
status: makeNodeStatuses(300, 300, 300, 301),
Expand All @@ -62,6 +64,8 @@ func TestBlockIfStalled(t *testing.T) {
// Then blockIfCatchup will block until a block is reported twice
func TestBlockIfCatchup(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

client := mockClient{
error: []error{nil, nil, nil},
status: makeNodeStatuses(301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 310),
Expand All @@ -84,6 +88,8 @@ func TestBlockIfCatchup(t *testing.T) {
// Then blockIfCatchup will return after the first status call.
func TestBlockIfCaughtUp(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

client := mockClient{
error: []error{nil, nil, nil},
status: makeNodeStatuses(300),
Expand Down Expand Up @@ -116,6 +122,8 @@ func (l *testlistener) onBlock(rpcs.EncodedBlockCert) {

func TestE2E(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

client := makeMockClient(
[]error{nil, nil, nil},
makeNodeStatuses(300, 301, 302, 302, 302, 302, 302, 302, 310, 320, 321, 321, 321, 322),
Expand Down Expand Up @@ -165,6 +173,8 @@ func TestE2E(t *testing.T) {

func TestAbortDuringStall(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

client := makeMockClient(
[]error{},
makeNodeStatuses(300),
Expand Down
6 changes: 6 additions & 0 deletions cmd/algoh/blockstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func makeTestBlock(round uint64) rpcs.EncodedBlockCert {

func TestConsecutiveBlocks(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sender := MockEventSender{}
bs := blockstats{log: &sender}

Expand All @@ -68,6 +70,8 @@ func TestConsecutiveBlocks(t *testing.T) {

func TestEventWithDetails(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sender := MockEventSender{}
bs := blockstats{log: &sender}

Expand Down Expand Up @@ -108,6 +112,8 @@ func TestEventWithDetails(t *testing.T) {

func TestAgreementTime(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sleepTime := 50 * time.Millisecond
testAttempts := 0
const maxTestAttempts = 10
Expand Down
3 changes: 3 additions & 0 deletions cmd/catchupsrv/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

func TestBlockToPath(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()
require.Equal(t, "00/00/000000", blockToPath(0))
require.Equal(t, "00/00/0000rs", blockToPath(1000))
require.Equal(t, "05/yc/05ycfo", blockToPath(10000500))
Expand All @@ -33,13 +34,15 @@ func TestBlockToPath(t *testing.T) {

func TestBlockToFileName(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()
require.Equal(t, "000000", blockToFileName(0))
require.Equal(t, "0000rs", blockToFileName(1000))
require.Equal(t, "05ycfo", blockToFileName(10000500))
require.Equal(t, "4ll2cic", blockToFileName(10012300500))
}

func TestBlockToString(t *testing.T) {
t.Parallel()
partitiontest.PartitionTest(t)
require.Equal(t, "0", blockToString(0))
require.Equal(t, "rs", blockToString(1000))
Expand Down
3 changes: 3 additions & 0 deletions cmd/goal/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

func TestParseMethodArgJSONtoByteSlice(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

makeRepeatSlice := func(size int, value string) []string {
slice := make([]string, size)
Expand Down Expand Up @@ -133,7 +134,9 @@ func TestParseMethodArgJSONtoByteSlice(t *testing.T) {
}

for i, test := range tests {
test := test
t.Run(fmt.Sprintf("index=%d", i), func(t *testing.T) {
t.Parallel()
applicationArgs := [][]byte{}
err := parseMethodArgJSONtoByteSlice(test.argTypes, test.jsonArgs, &applicationArgs)
require.NoError(t, err)
Expand Down
10 changes: 5 additions & 5 deletions cmd/goal/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestEnsureDataDirReturnsWhenDataDirIsProvided(t *testing.T) {
func TestEnsureDataDirReturnsWhenDataDirIsProvided(t *testing.T) { // nolint:paralleltest // Sets shared OS environment variable.
partitiontest.PartitionTest(t)
expectedDir := "~/.algorand"
os.Setenv("ALGORAND_DATA", expectedDir)
actualDir := datadir.EnsureFirstDataDir()
require.Equal(t, expectedDir, actualDir)
}

func TestEnsureDataDirReturnsWhenWorkDirIsProvided(t *testing.T) {
func TestEnsureDataDirReturnsWhenWorkDirIsProvided(t *testing.T) { // nolint:paralleltest // Sets shared OS environment variable.
partitiontest.PartitionTest(t)
expectedDir, err := os.Getwd()
if err != nil {
Expand All @@ -44,7 +44,7 @@ func TestEnsureDataDirReturnsWhenWorkDirIsProvided(t *testing.T) {
require.Equal(t, expectedDir, actualDir)
}

func TestEnsureDataDirReturnsWhenRelPath1IsProvided(t *testing.T) {
func TestEnsureDataDirReturnsWhenRelPath1IsProvided(t *testing.T) { // nolint:paralleltest // Sets shared OS environment variable.
partitiontest.PartitionTest(t)
expectedDir, err := os.Getwd()
if err != nil {
Expand All @@ -55,7 +55,7 @@ func TestEnsureDataDirReturnsWhenRelPath1IsProvided(t *testing.T) {
require.Equal(t, expectedDir, actualDir)
}

func TestEnsureDataDirReturnsWhenRelPath2IsProvided(t *testing.T) {
func TestEnsureDataDirReturnsWhenRelPath2IsProvided(t *testing.T) { // nolint:paralleltest // Sets shared OS environment variable.
partitiontest.PartitionTest(t)
expectedDir, err := os.Getwd()
if err != nil {
Expand All @@ -66,7 +66,7 @@ func TestEnsureDataDirReturnsWhenRelPath2IsProvided(t *testing.T) {
require.Equal(t, expectedDir, actualDir)
}

func TestEnsureDataDirReturnsWhenRelPath3IsProvided(t *testing.T) {
func TestEnsureDataDirReturnsWhenRelPath3IsProvided(t *testing.T) { // nolint:paralleltest // Sets shared OS environment variable.
partitiontest.PartitionTest(t)
expectedDir, err := os.Getwd()
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions cmd/goal/formatting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (

func TestUnicodePrintable(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

testUnicodePrintableStrings := []struct {
testString string
isPrintable bool
Expand All @@ -45,6 +47,7 @@ func TestUnicodePrintable(t *testing.T) {

func TestNewAppCallBytes(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

acb := newAppCallBytes("int:3")
require.Equal(t, "int", acb.Encoding)
Expand All @@ -57,6 +60,8 @@ func TestNewAppCallBytes(t *testing.T) {

func TestNewBoxRef(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

br := newBoxRef("str:hello")
require.EqualValues(t, 0, br.appID)
require.Equal(t, "str", br.name.Encoding)
Expand All @@ -73,6 +78,8 @@ func TestNewBoxRef(t *testing.T) {

func TestStringsToBoxRefs(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

brs := stringsToBoxRefs([]string{"77,str:hello", "55,int:6", "int:88"})
require.EqualValues(t, 77, brs[0].appID)
require.EqualValues(t, 55, brs[1].appID)
Expand Down Expand Up @@ -108,7 +115,9 @@ func TestBytesToAppCallBytes(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.expected, func(t *testing.T) {
t.Parallel()
acb := encodeBytesAsAppCallBytes(tc.input)
require.Equal(t, tc.expected, acb)
})
Expand Down
2 changes: 2 additions & 0 deletions cmd/goal/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

func TestInspect(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

var err error

var empty transactions.SignedTxn
Expand Down
3 changes: 3 additions & 0 deletions cmd/goal/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var isAlnum = regexp.MustCompile(`^[a-zA-Z0-9_]*$`)

func TestGetMissingCatchpointLabel(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()
tests := []struct {
name string
URL string
Expand Down Expand Up @@ -84,7 +85,9 @@ func TestGetMissingCatchpointLabel(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, test.expectedErr, test.statusCode)
}))
Expand Down
17 changes: 17 additions & 0 deletions cmd/tealdbg/cdtSession_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (

func TestCdtSessionProto11Common(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -97,6 +99,8 @@ func TestCdtSessionProto11Common(t *testing.T) {

func TestCdtSessionProto11Breakpoints(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -182,6 +186,8 @@ func TestCdtSessionProto11Breakpoints(t *testing.T) {

func TestCdtSessionProto11Events(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -216,6 +222,8 @@ func TestCdtSessionProto11Events(t *testing.T) {

func TestCdtSessionProto11Controls(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -260,6 +268,8 @@ func TestCdtSessionProto11Controls(t *testing.T) {

func TestCdtSessionProto11Evaluate(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -299,6 +309,8 @@ func TestCdtSessionProto11Evaluate(t *testing.T) {

func TestCdtSessionProto11CallOnFunc(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -388,6 +400,8 @@ func TestCdtSessionProto11CallOnFunc(t *testing.T) {

func TestCdtSessionProto11GetProps(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -422,6 +436,8 @@ func TestCdtSessionProto11GetProps(t *testing.T) {

func TestCdtSessionStateToEvent(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down Expand Up @@ -461,6 +477,7 @@ func TestCdtSessionStateToEvent(t *testing.T) {

func TestCdtSessionGetObjects(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()
sid := "test"
dbg := MockDebugControl{}
ch := make(chan Notification)
Expand Down
6 changes: 6 additions & 0 deletions cmd/tealdbg/cdtdbg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (

func TestCdtHandlers(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

params := CdtFrontendParams{
router: mux.NewRouter(),
apiAddress: "127.0.0.1:12345",
Expand Down Expand Up @@ -151,6 +153,8 @@ func (c *MockDebugControl) GetStates(s *logic.DebugState) AppState {

func TestCdtFrontendSessionStarted(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

params := CdtFrontendParams{
router: mux.NewRouter(),
apiAddress: "127.0.0.1:12345",
Expand Down Expand Up @@ -188,6 +192,8 @@ func TestCdtFrontendSessionStarted(t *testing.T) {

func TestCdtAdapterSessionEnded(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

params := CdtFrontendParams{
router: mux.NewRouter(),
apiAddress: "127.0.0.1:12345",
Expand Down
Loading

0 comments on commit 4bbedc0

Please sign in to comment.