From f5ae8fa3c6e980f4c2ea43daba7761c3f379f03d Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 14 Jul 2022 22:08:31 -0700 Subject: Fix flaky race test `ignoredError.err` was being used in a Goroutine handler, but the value of `ignoredError` changes with each test case. To avoid a race, make a local copy of the error before each Goroutine runs. Closes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/590 --- internal/sshd/connection_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/sshd/connection_test.go b/internal/sshd/connection_test.go index 3a5f664..8874b07 100644 --- a/internal/sshd/connection_test.go +++ b/internal/sshd/connection_test.go @@ -225,9 +225,10 @@ func TestSessionsMetrics(t *testing.T) { } { t.Run(ignoredError.desc, func(t *testing.T) { conn, chans = setup(1, newChannel) + ignored := ignoredError.err conn.handleRequests(context.Background(), nil, chans, func(*ssh.ServerConn, ssh.Channel, <-chan *ssh.Request) error { close(chans) - return ignoredError.err + return ignored }) require.InDelta(t, initialSessionsTotal+2+float64(i), testutil.ToFloat64(metrics.SliSshdSessionsTotal), 0.1) -- cgit v1.2.1