From b3681c4cd34e6e2e4519910c612711436d27f5fc Mon Sep 17 00:00:00 2001 From: Milos Gajdos Date: Wed, 29 Nov 2023 21:40:20 +0000 Subject: [PATCH] feat: add tparallel linter to improve handling parallel tests This linter both prevents parallel test races as well as suggests parallel tests where appropriate: See: https://github.com/moricho/tparallel Signed-off-by: Milos Gajdos --- .golangci.yml | 1 + internal/dcontext/trace_test.go | 2 +- registry/storage/driver/errors_test.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index a6dfe5ca..ec637d63 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,6 +12,7 @@ linters: - bodyclose - prealloc - errcheck + - tparallel linters-settings: revive: diff --git a/internal/dcontext/trace_test.go b/internal/dcontext/trace_test.go index bb6d1779..719fa37b 100644 --- a/internal/dcontext/trace_test.go +++ b/internal/dcontext/trace_test.go @@ -34,7 +34,7 @@ func TestWithTrace(t *testing.T) { } ctx, done := WithTrace(Background()) - defer done("this will be emitted at end of test") + t.Cleanup(func() { done("this will be emitted at end of test") }) tests := append(base, valueTestCase{ key: "trace.func", diff --git a/registry/storage/driver/errors_test.go b/registry/storage/driver/errors_test.go index f692466f..5831dd98 100644 --- a/registry/storage/driver/errors_test.go +++ b/registry/storage/driver/errors_test.go @@ -33,6 +33,7 @@ func TestErrorFormat(t *testing.T) { } func TestErrors(t *testing.T) { + t.Parallel() drvName := "foo" testCases := []struct {