diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2021-11-16 03:05:08 +0000 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2021-11-16 03:05:08 +0000 |
commit | b1c1e5fa06b31cca25799da3b42e97b5f71dbbac (patch) | |
tree | 10fec67074fe71a2430cad5105d893bd3e1e17d5 | |
parent | 9d8a14e5bac26ac5dd303d631583d3ed49f6e64c (diff) | |
parent | 33180313d805212353d0526e3d95d49fe70eed91 (diff) | |
download | gitlab-shell-b1c1e5fa06b31cca25799da3b42e97b5f71dbbac.tar.gz |
Merge branch 'id-fix-flaky-test' into 'main'
Refactor flaky test case in sshd_test
See merge request gitlab-org/gitlab-shell!545
-rw-r--r-- | internal/sshd/sshd_test.go | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/internal/sshd/sshd_test.go b/internal/sshd/sshd_test.go index 455a830..0c6a8ec 100644 --- a/internal/sshd/sshd_test.go +++ b/internal/sshd/sshd_test.go @@ -48,8 +48,7 @@ func TestListenAndServe(t *testing.T) { } func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testing.T) { - s := setupServerWithProxyProtocolEnabled(t) - defer s.Shutdown() + setupServerWithProxyProtocolEnabled(t) client, err := ssh.Dial("tcp", serverUrl, clientConfig(t)) if client != nil { @@ -57,7 +56,7 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin } require.Error(t, err, "Expected plain SSH request to be failed") - require.Equal(t, err.Error(), "ssh: handshake failed: EOF") + require.Regexp(t, "ssh: handshake failed", err.Error()) } func TestCorrelationId(t *testing.T) { @@ -227,14 +226,5 @@ func holdSession(t *testing.T, c *ssh.Client) { } func verifyStatus(t *testing.T, s *Server, st status) { - for i := 5; i < 500; i += 50 { - if s.getStatus() == st { - break - } - - // Sleep incrementally ~2s in total - time.Sleep(time.Duration(i) * time.Millisecond) - } - - require.Equal(t, st, s.getStatus()) + require.Eventually(t, func() bool { return s.getStatus() == st }, 2*time.Second, time.Millisecond) } |