summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2022-07-14 22:08:31 -0700
committerStan Hu <stanhu@gmail.com>2022-07-14 22:08:31 -0700
commitf5ae8fa3c6e980f4c2ea43daba7761c3f379f03d (patch)
treefadf55fa1125c93afdbe91645c78a162d5ec5c56
parent2d25f8277c36288500fae1fdcf487e76d38ed0f3 (diff)
downloadgitlab-shell-f5ae8fa3c6e980f4c2ea43daba7761c3f379f03d.tar.gz
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
-rw-r--r--internal/sshd/connection_test.go3
1 files changed, 2 insertions, 1 deletions
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)