summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Drozdov <idrozdov@gitlab.com>2021-11-15 18:15:03 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2021-11-15 18:22:47 +0300
commit33180313d805212353d0526e3d95d49fe70eed91 (patch)
tree10fec67074fe71a2430cad5105d893bd3e1e17d5
parent9d8a14e5bac26ac5dd303d631583d3ed49f6e64c (diff)
downloadgitlab-shell-id-fix-flaky-test.tar.gz
Refactor flaky test case in sshd_testid-fix-flaky-test
- Use require.Regexp to expect ssh handshake error - Use require.Eventually to refactor verifyStatus
-rw-r--r--internal/sshd/sshd_test.go16
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)
}