From a04fa17d3719e5435c35a599cf566630a08108a8 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 13 Jun 2023 00:45:56 +0300 Subject: use race detector for the tests and also run tests in parallel --- Taskfile.yml | 2 +- internal/config/config_test.go | 3 +++ internal/quorum/quorum_test.go | 1 + internal/utils/string_test.go | 1 + internal/vote/vote_test.go | 3 +++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index 62aefaa..886e8b6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -7,4 +7,4 @@ tasks: test: cmds: - go clean -testcache - - go test ./... -v + - go test ./... -v -race diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 973797a..2fcfefb 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -7,6 +7,7 @@ import ( ) func TestNodeNumber(t *testing.T) { + t.Parallel() conf := Config{Nodes: []string{"localhost:1234", "hamburger:4321"}} num, err := conf.NodeNumber("localhost") @@ -32,6 +33,7 @@ func TestNodeNumber(t *testing.T) { } func TestIsNode(t *testing.T) { + t.Parallel() conf := Config{Nodes: []string{"localhost:1234", "hamburger:4321"}} remoteAddr := "localhost:323232" @@ -46,6 +48,7 @@ func TestIsNode(t *testing.T) { } func TestIsNodeWithLookup(t *testing.T) { + t.Parallel() conf := Config{Nodes: []string{"localhost:1234", "hamburger:4321"}} lookupIP := func(addr string) ([]net.IP, error) { diff --git a/internal/quorum/quorum_test.go b/internal/quorum/quorum_test.go index ad78938..f5d847e 100644 --- a/internal/quorum/quorum_test.go +++ b/internal/quorum/quorum_test.go @@ -11,6 +11,7 @@ import ( var inOneHour = time.Now().Add(1 * time.Hour) func TestScore(t *testing.T) { + t.Parallel() var ( conf = config.Config{Nodes: []string{"foo:1234", "bar:4321", "baz:3444"}} quo = New(conf) diff --git a/internal/utils/string_test.go b/internal/utils/string_test.go index 10a7f83..dfdc893 100644 --- a/internal/utils/string_test.go +++ b/internal/utils/string_test.go @@ -5,6 +5,7 @@ import ( ) func TestStripPort(t *testing.T) { + t.Parallel() if "localhost" != StripPort("localhost:1234") { t.Errorf("unable to split port from \"localhost:1234\"") } diff --git a/internal/vote/vote_test.go b/internal/vote/vote_test.go index a2a851b..cccb1be 100644 --- a/internal/vote/vote_test.go +++ b/internal/vote/vote_test.go @@ -7,6 +7,7 @@ import ( ) func TestVote(t *testing.T) { + t.Parallel() v, _ := New([]string{"foo", "bar", "baz", "bay"}) hostname, _ := os.Hostname() @@ -28,6 +29,7 @@ func TestVote(t *testing.T) { } func TestVoteExpiry(t *testing.T) { + t.Parallel() v, _ := New([]string{"foo", "bar", "baz", "bay"}) // Set expiry 1h into the future @@ -44,6 +46,7 @@ func TestVoteExpiry(t *testing.T) { } func TestMarshalling(t *testing.T) { + t.Parallel() v, _ := New([]string{"foo", "bar", "baz", "bay"}) jsonStr, err := v.ToJSON() if err != nil { -- cgit v1.2.3