From cc5559dfc4354e0b32a0f56bf8f5dfe0429bf147 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Fri, 10 Aug 2018 10:07:32 +0200 Subject: [PATCH] address review comments --- client/proposer/BUILD.bazel | 6 ++-- .../{racy_test.go => service_norace_test.go} | 0 client/syncer/BUILD.bazel | 6 ++-- .../{racy_test.go => service_norace_test.go} | 0 shared/p2p/BUILD.bazel | 10 ++++-- ...{racy_test.go => discovery_norace_test.go} | 29 --------------- shared/p2p/service_norace_test.go | 35 +++++++++++++++++++ 7 files changed, 48 insertions(+), 38 deletions(-) rename client/proposer/{racy_test.go => service_norace_test.go} (100%) rename client/syncer/{racy_test.go => service_norace_test.go} (100%) rename shared/p2p/{racy_test.go => discovery_norace_test.go} (70%) create mode 100644 shared/p2p/service_norace_test.go diff --git a/client/proposer/BUILD.bazel b/client/proposer/BUILD.bazel index f5479e2ec967..08d995834dfa 100644 --- a/client/proposer/BUILD.bazel +++ b/client/proposer/BUILD.bazel @@ -41,11 +41,11 @@ go_test( # by default gazelle tries to add all the test files to the first # go_test; we need to exclude the tests that we want to configure # in a particular way -# gazelle:exclude racy_test.go +# gazelle:exclude service_norace_test.go go_test( - name = "go_racy_test", - srcs = ["racy_test.go"], + name = "go_norace_test", + srcs = ["service_norace_test.go"], embed = [":go_default_library"], race = "off", # TODO(#377): fix issues with race detection testing. deps = [ diff --git a/client/proposer/racy_test.go b/client/proposer/service_norace_test.go similarity index 100% rename from client/proposer/racy_test.go rename to client/proposer/service_norace_test.go diff --git a/client/syncer/BUILD.bazel b/client/syncer/BUILD.bazel index a85884465edf..320651cc823e 100644 --- a/client/syncer/BUILD.bazel +++ b/client/syncer/BUILD.bazel @@ -52,11 +52,11 @@ go_test( # by default gazelle tries to add all the test files to the first # go_test; we need to exclude the tests that we want to configure # in a particular way -# gazelle:exclude racy_test.go +# gazelle:exclude service_norace_test.go go_test( - name = "go_racy_test", - srcs = ["racy_test.go"], + name = "go_norace_test", + srcs = ["service_norace_test.go"], embed = [":go_default_library"], race = "off", # TODO(#377): fix issues with race detection testing. deps = [ diff --git a/client/syncer/racy_test.go b/client/syncer/service_norace_test.go similarity index 100% rename from client/syncer/racy_test.go rename to client/syncer/service_norace_test.go diff --git a/shared/p2p/BUILD.bazel b/shared/p2p/BUILD.bazel index f9eb4a67cf21..35a294e8fb13 100644 --- a/shared/p2p/BUILD.bazel +++ b/shared/p2p/BUILD.bazel @@ -55,11 +55,15 @@ go_test( # by default gazelle tries to add all the test files to the first # go_test; we need to exclude the tests that we want to configure # in a particular way -# gazelle:exclude racy_test.go +# gazelle:exclude discovery_norace_test.go +# gazelle:exclude service_norace_test.go go_test( - name = "go_racy_test", - srcs = ["racy_test.go"], + name = "go_norace_test", + srcs = [ + "discovery_norace_test.go", + "service_norace_test.go", + ], embed = [":go_default_library"], race = "off", # TODO(#377): fix issues with race detection testing. deps = [ diff --git a/shared/p2p/racy_test.go b/shared/p2p/discovery_norace_test.go similarity index 70% rename from shared/p2p/racy_test.go rename to shared/p2p/discovery_norace_test.go index 173f8f2f49f3..2d42402f111b 100644 --- a/shared/p2p/racy_test.go +++ b/shared/p2p/discovery_norace_test.go @@ -10,7 +10,6 @@ import ( swarmt "github.com/libp2p/go-libp2p-swarm/testing" mdns "github.com/libp2p/go-libp2p/p2p/discovery" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" - logTest "github.com/sirupsen/logrus/hooks/test" ) var _ = mdns.Notifee(&discovery{}) @@ -63,31 +62,3 @@ func TestStartDiscovery_HandlePeerFound(t *testing.T) { expectPeers(t, a, 2) expectPeers(t, b, 2) } - -func TestLifecycle(t *testing.T) { - hook := logTest.NewGlobal() - - s, err := NewServer() - if err != nil { - t.Fatalf("Could not start a new server: %v", err) - } - - s.Start() - msg := hook.Entries[0].Message - want := "Starting service" - if msg != want { - t.Errorf("incorrect log. wanted: %s. got: %v", want, msg) - } - - s.Stop() - msg = hook.LastEntry().Message - want = "Stopping service" - if msg != want { - t.Errorf("incorrect log. wanted: %s. got: %v", want, msg) - } - - // The context should have been cancelled. - if s.ctx.Err() == nil { - t.Error("Context was not cancelled") - } -} diff --git a/shared/p2p/service_norace_test.go b/shared/p2p/service_norace_test.go new file mode 100644 index 000000000000..c183db51431c --- /dev/null +++ b/shared/p2p/service_norace_test.go @@ -0,0 +1,35 @@ +package p2p + +import ( + "testing" + + logTest "github.com/sirupsen/logrus/hooks/test" +) + +func TestLifecycle(t *testing.T) { + hook := logTest.NewGlobal() + + s, err := NewServer() + if err != nil { + t.Fatalf("Could not start a new server: %v", err) + } + + s.Start() + msg := hook.Entries[0].Message + want := "Starting service" + if msg != want { + t.Errorf("incorrect log. wanted: %s. got: %v", want, msg) + } + + s.Stop() + msg = hook.LastEntry().Message + want = "Stopping service" + if msg != want { + t.Errorf("incorrect log. wanted: %s. got: %v", want, msg) + } + + // The context should have been cancelled. + if s.ctx.Err() == nil { + t.Error("Context was not cancelled") + } +}