Skip to content
Snippets Groups Projects
Unverified Commit 396287b6 authored by Steve Azzopardi's avatar Steve Azzopardi
Browse files

Fix TestInteractiveTerminal flaky test

Sometime the tty STDOUT/STDERR wasn't always the same, instead of
looping 3 times, loop for 5 seconds or until the word `Linux` is
present.

If the `Linux` is not present and 5 seconds pass, the test will fail.
parent bbd7c711
Branches
Tags
No related merge requests found
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"os" "os"
"strings"
"testing" "testing"
"time" "time"
...@@ -89,15 +90,23 @@ func TestInteractiveTerminal(t *testing.T) { ...@@ -89,15 +90,23 @@ func TestInteractiveTerminal(t *testing.T) {
err = webSocket.WriteMessage(websocket.BinaryMessage, []byte("uname\n")) err = webSocket.WriteMessage(websocket.BinaryMessage, []byte("uname\n"))
require.NoError(t, err) require.NoError(t, err)
var unameResult string readStarted := time.Now()
for i := 0; i < 3; i++ { var tty []byte
for time.Since(readStarted) < 5*time.Second {
typ, b, err := webSocket.ReadMessage() typ, b, err := webSocket.ReadMessage()
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, websocket.BinaryMessage, typ) require.Equal(t, websocket.BinaryMessage, typ)
unameResult = string(b) tty = append(tty, b...)
if strings.Contains(string(b), "Linux") {
break
}
time.Sleep(50 * time.Microsecond)
} }
assert.Contains(t, unameResult, "Linux") t.Log(string(tty))
assert.Contains(t, string(tty), "Linux")
} }
func TestCommandExecutor_Connect_Timeout(t *testing.T) { func TestCommandExecutor_Connect_Timeout(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment