Parallel tests don't reinitialize variables
In some of our tests we don't reinitialize the test variable, this can cause problems to go undetected (https://gist.github.com/posener/92a55c4cd441fc5e5e85f27bca008721).
We need to:
- fix such tests
- add a linter check to avoid this problem in the future
e.g.
❯ TEST_PACKAGES=./internal/gitaly/service/operations/ make test-go
✓ internal/gitaly/service/operations (4.985s)
DONE 602 tests in 6.573s
with the correct fix:
~/gitlab-development-kit/gitaly master
❯ git diff
diff --git a/internal/gitaly/service/operations/apply_patch_test.go b/internal/gitaly/service/operations/apply_patch_test.go
index 183f73b558..a9923c99ac 100644
--- a/internal/gitaly/service/operations/apply_patch_test.go
+++ b/internal/gitaly/service/operations/apply_patch_test.go
@@ -299,6 +299,8 @@ To restore the original branch and stop patching, run "git am --abort".
expectedErr: errPatchingFailed,
},
} {
+ tc := tc
+
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
We can see that the test is actually broken
~/gitlab-development-kit/gitaly master
❯ TEST_PACKAGES=./internal/gitaly/service/operations/ make test-go
✖ internal/gitaly/service/operations (5.363s)
=== Failed
=== FAIL: internal/gitaly/service/operations TestUserApplyPatch/creating_the_first_branch_does_not_work (0.02s)
apply_patch_test.go:339: [-c user.name=Scrooge McDuck -c user.email=scrooge@mcduck.com -C /tmp/gitaly-4220925412/1144884104/storages.d/default/@hashed/83/5a/835ad074761a8c8dae8d53ab1d7b76bf3a185a3a43c2edd9a1a2e510506f3a91.git commit-tree -F - 94651e8fb1ccc4735cb72bdac488d15e0b67c34d -p ]
apply_patch_test.go:339: fatal: not a valid object name
:
apply_patch_test.go:339: exit status 128
--- FAIL: TestUserApplyPatch/creating_the_first_branch_does_not_work (0.02s)
=== FAIL: internal/gitaly/service/operations TestUserApplyPatch (2.45s)
DONE 602 tests, 2 failures in 7.154s
make: *** [Makefile:377: test-go] Error 1