From ddc173f801870eac1f9fec46a3994a427757aae9 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 14 Apr 2020 14:13:34 +0200 Subject: [PATCH] eth: fixed data race in tests Due to the reuse of error channels throughout the tests, the golang race tester complains to test use `go test -count=1 -run=TestForkIDSplit ./... -race` --- eth/protocol_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/eth/protocol_test.go b/eth/protocol_test.go index a313e4e6cf..67246643a0 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -211,12 +211,12 @@ func TestForkIDSplit(t *testing.T) { peerNoFork = newPeer(64, p2p.NewPeer(enode.ID{1}, "", nil), p2pNoFork, nil) peerProFork = newPeer(64, p2p.NewPeer(enode.ID{2}, "", nil), p2pProFork, nil) - errc = make(chan error, 2) - go func() { errc <- ethNoFork.handle(peerProFork) }() - go func() { errc <- ethProFork.handle(peerNoFork) }() + errc2 := make(chan error, 2) + go func() { errc2 <- ethNoFork.handle(peerProFork) }() + go func() { errc2 <- ethProFork.handle(peerNoFork) }() select { - case err := <-errc: + case err := <-errc2: t.Fatalf("homestead nofork <-> profork failed: %v", err) case <-time.After(250 * time.Millisecond): p2pNoFork.Close() @@ -230,12 +230,12 @@ func TestForkIDSplit(t *testing.T) { peerNoFork = newPeer(64, p2p.NewPeer(enode.ID{1}, "", nil), p2pNoFork, nil) peerProFork = newPeer(64, p2p.NewPeer(enode.ID{2}, "", nil), p2pProFork, nil) - errc = make(chan error, 2) - go func() { errc <- ethNoFork.handle(peerProFork) }() - go func() { errc <- ethProFork.handle(peerNoFork) }() + errc3 := make(chan error, 2) + go func() { errc3 <- ethNoFork.handle(peerProFork) }() + go func() { errc3 <- ethProFork.handle(peerNoFork) }() select { - case err := <-errc: + case err := <-errc3: if want := errResp(ErrForkIDRejected, forkid.ErrLocalIncompatibleOrStale.Error()); err.Error() != want.Error() { t.Fatalf("fork ID rejection error mismatch: have %v, want %v", err, want) }