test: scaletest/reconnectingpty: use TerminalReader (#15079)

Fixes: https://github.com/coder/internal/issues/98
This commit is contained in:
Marcin Tojek
2024-10-16 11:10:32 +02:00
committed by GitHub
parent 687b4dd41c
commit 2564f9c823

View File

@ -3,6 +3,7 @@ package reconnectingpty_test
import (
"bytes"
"context"
"io"
"testing"
"time"
@ -22,7 +23,6 @@ import (
func Test_Runner(t *testing.T) {
t.Parallel()
t.Skip("https://github.com/coder/internal/issues/98")
t.Run("OK", func(t *testing.T) {
t.Parallel()
@ -43,14 +43,16 @@ func Test_Runner(t *testing.T) {
logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
logStr := logs.String()
t.Log("Runner logs:\n\n" + logStr)
require.NoError(t, err)
require.Contains(t, logStr, "Output:")
tr := testutil.NewTerminalReader(t, logs)
err = tr.ReadUntilString(ctx, "Output:")
require.NoError(t, err)
// OSX: Output:\n\thello world\n
// Win: Output:\n\t\x1b[2J\x1b[m\x1b[H\x1b]0;Administrator: C:\\Program Files\\PowerShell\\7\\pwsh.exe\a\x1b[?25hhello world\n
require.Contains(t, logStr, "hello world\n")
err = tr.ReadUntilString(ctx, "hello world")
require.NoError(t, err)
})
t.Run("NoLogOutput", func(t *testing.T) {
@ -71,11 +73,12 @@ func Test_Runner(t *testing.T) {
logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
logStr := logs.String()
t.Log("Runner logs:\n\n" + logStr)
require.NoError(t, err)
require.NotContains(t, logStr, "Output:")
tr := testutil.NewTerminalReader(t, logs)
err = tr.ReadUntilString(ctx, "Output:")
require.Error(t, err)
require.ErrorIs(t, err, io.EOF)
})
t.Run("Timeout", func(t *testing.T) {
@ -199,8 +202,7 @@ func Test_Runner(t *testing.T) {
Init: workspacesdk.AgentReconnectingPTYInit{
Command: "echo 'hello world'; sleep 1",
},
ExpectOutput: "hello world",
LogOutput: false,
LogOutput: true,
})
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
@ -208,8 +210,10 @@ func Test_Runner(t *testing.T) {
logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
logStr := logs.String()
t.Log("Runner logs:\n\n" + logStr)
require.NoError(t, err)
tr := testutil.NewTerminalReader(t, logs)
err = tr.ReadUntilString(ctx, "hello world")
require.NoError(t, err)
})
@ -223,8 +227,7 @@ func Test_Runner(t *testing.T) {
Init: workspacesdk.AgentReconnectingPTYInit{
Command: "echo 'hello world'; sleep 1",
},
ExpectOutput: "bello borld",
LogOutput: false,
LogOutput: true,
})
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
@ -232,10 +235,12 @@ func Test_Runner(t *testing.T) {
logs := bytes.NewBuffer(nil)
err := runner.Run(ctx, "1", logs)
logStr := logs.String()
t.Log("Runner logs:\n\n" + logStr)
require.NoError(t, err)
tr := testutil.NewTerminalReader(t, logs)
err = tr.ReadUntilString(ctx, "bello borld")
require.Error(t, err)
require.ErrorContains(t, err, `expected string "bello borld" not found`)
require.ErrorIs(t, err, io.EOF)
})
})
}