Refactor docker terminal tests

parent 11d02d05
......@@ -8,6 +8,7 @@ import (
"time"
"github.com/docker/docker/api/types"
"gitlab.com/gitlab-org/gitlab-runner/common"
"gitlab.com/gitlab-org/gitlab-runner/helpers/docker"
terminalsession "gitlab.com/gitlab-org/gitlab-runner/session/terminal"
......@@ -95,7 +96,7 @@ func (t terminalConn) Start(w http.ResponseWriter, r *http.Request, timeoutCh, d
exec, err := t.client.ContainerExecCreate(t.ctx, t.containerID, execConfig)
if err != nil {
t.logger.Errorln("Failed to create exec container for terminal:", err)
http.Error(w, "failed to create exec to build container", http.StatusInternalServerError)
http.Error(w, "failed to create exec for build container", http.StatusInternalServerError)
return
}
......
......@@ -67,23 +67,23 @@ func TestInteractiveTerminal(t *testing.T) {
"Authorization": []string{build.Session.Token},
}
var retries int
var webSocket *websocket.Conn
for retries < 500 {
conn, resp, err := websocket.DefaultDialer.Dial(u.String(), headers)
if err != nil {
retries++
time.Sleep(50 * time.Millisecond)
continue
var resp *http.Response
started := time.Now()
for time.Since(started) < 25*time.Second {
webSocket, resp, err = websocket.DefaultDialer.Dial(u.String(), headers)
if err == nil {
break
}
require.NoError(t, err)
require.NotNil(t, conn)
require.Equal(t, http.StatusSwitchingProtocols, resp.StatusCode)
webSocket = conn
break
time.Sleep(50 * time.Millisecond)
}
require.NotNil(t, webSocket)
require.Equal(t, http.StatusSwitchingProtocols, resp.StatusCode)
defer webSocket.Close()
err = webSocket.WriteMessage(websocket.BinaryMessage, []byte("uname\n"))
......@@ -406,7 +406,15 @@ func TestTerminalConn_Start(t *testing.T) {
}
}()
time.Sleep(5 * time.Second)
started := time.Now()
for time.Since(started) < 5*time.Second {
if !session.Connected() {
break
}
time.Sleep(50 * time.Microsecond)
}
assert.False(t, session.Connected())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment