From 5fec3d1bb93a38f95c65171021179d924c459979 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 9 Jun 2021 12:26:49 -0400 Subject: [PATCH 1/4] ci: use latest Go version and enable -race Also remove module cache, because downloading from the module proxy is faster than using the cache. --- .circleci/config.yml | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6507b0ca7..bf4fac672 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ version: 2.1 executors: go: docker: - - image: docker.mirror.hashicorp.services/circleci/golang:1.14.1 + - image: docker.mirror.hashicorp.services/circleci/golang:1.16 environment: - TEST_RESULTS: /tmp/test-results # path to where test results are saved @@ -13,20 +13,8 @@ jobs: executor: go steps: - checkout - - # Restore go module cache if there is one - - restore_cache: - keys: - - serf-modcache-v1-{{ checksum "go.mod" }} - - run: go mod download - # Save go module cache if the go.mod file has changed - - save_cache: - key: serf-modcache-v1-{{ checksum "go.mod" }} - paths: - - "/go/pkg/mod" - # check go fmt output because it does not report non-zero when there are fmt changes - run: name: check go fmt @@ -45,12 +33,6 @@ jobs: - checkout - run: mkdir -p $TEST_RESULTS - run: make bin - - # Restore go module cache if there is one - - restore_cache: - keys: - - serf-modcache-v1-{{ checksum "go.mod" }} - - run: sudo apt-get update && sudo apt-get install -y rsyslog - run: sudo service rsyslog start # run go tests with gotestsum From 6b6085d02499ffcb6496507ae4133f9b94eef695 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 9 Jun 2021 12:48:20 -0400 Subject: [PATCH 2/4] testing: use Errorf from a gourtine It is not safe to call Fatalf from a goroutine because Fatalf calls runtime.Goexit which exits the current goroutine. That will not end the test when run from a different goroutine. Calling Errorf and returning does the right thing. --- serf/serf_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/serf/serf_test.go b/serf/serf_test.go index ce916e277..a0efc26a9 100644 --- a/serf/serf_test.go +++ b/serf/serf_test.go @@ -2034,11 +2034,12 @@ func TestSerf_Query(t *testing.T) { } q := e.(*Query) if err := q.Respond([]byte("test")); err != nil { - t.Fatalf("err: %v", err) + t.Errorf("err: %v", err) } return case <-time.After(time.Second): - t.Fatalf("timeout") + t.Errorf("timeout") + return } } }() @@ -2138,11 +2139,12 @@ func TestSerf_Query_Filter(t *testing.T) { } q := e.(*Query) if err := q.Respond([]byte("test")); err != nil { - t.Fatalf("err: %v", err) + t.Errorf("err: %v", err) } return case <-time.After(time.Second): - t.Fatalf("timeout") + t.Errorf("timeout") + return } } }() From c99e25fb68646777b0c2c8f59c7e419913471346 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 9 Jun 2021 12:58:28 -0400 Subject: [PATCH 3/4] darwin/386 is no longer supported by the Go toolchain --- scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build.sh b/scripts/build.sh index 97949831d..7b28fa3cb 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -36,7 +36,7 @@ fi echo "==> Building..." gox \ -os="${XC_OS}" \ - -osarch="!darwin/arm" \ + -osarch="!darwin/arm !darwin/386" \ -arch="${XC_ARCH}" \ -ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}${GIT_DIRTY}'" \ -output "pkg/{{.OS}}_{{.Arch}}/serf" \ From ac85eef7fa1c0e6561a3b4f384a6247d0d063859 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 9 Jun 2021 13:13:06 -0400 Subject: [PATCH 4/4] Fix serf.TestSerf_RemoveFailed_eventsLeave flake The test was not sleeping long enough, and was frequently missing the 'EventMemberFailed' event. By sleeping a bit logner this test seems to pass reliably. --- serf/event_test.go | 1 + serf/serf_test.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/serf/event_test.go b/serf/event_test.go index 08c339f79..083810cb1 100644 --- a/serf/event_test.go +++ b/serf/event_test.go @@ -9,6 +9,7 @@ import ( // testEvents tests that the given node had the given sequence of events // on the event channel. func testEvents(t *testing.T, ch <-chan Event, node string, expected []EventType) { + t.Helper() actual := make([]EventType, 0, len(expected)) TESTEVENTLOOP: diff --git a/serf/serf_test.go b/serf/serf_test.go index a0efc26a9..2d8fa1d54 100644 --- a/serf/serf_test.go +++ b/serf/serf_test.go @@ -459,7 +459,7 @@ func TestSerf_RemoveFailed_eventsLeave(t *testing.T) { t.Fatalf("err: %v", err) } - time.Sleep(s2Config.MemberlistConfig.ProbeInterval * 3) + time.Sleep(s2Config.MemberlistConfig.ProbeInterval * 5) if err := s1.RemoveFailedNode(s2Config.NodeName); err != nil { t.Fatalf("err: %v", err) @@ -2950,7 +2950,7 @@ func waitUntilNumNodes(t *testing.T, desiredNodes int, serfs ...*Serf) { t.Helper() for i, s := range serfs { if n := s.NumNodes(); desiredNodes != n { - r.Fatalf("s%d got %d expected %d", (i + 1), n, desiredNodes) + r.Fatalf("s%d got %d expected %d", i+1, n, desiredNodes) } } })