mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
test: scaletest/reconnectingpty: use TerminalReader
(#15079)
Fixes: https://github.com/coder/internal/issues/98
This commit is contained in:
@ -3,6 +3,7 @@ package reconnectingpty_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -22,7 +23,6 @@ import (
|
|||||||
|
|
||||||
func Test_Runner(t *testing.T) {
|
func Test_Runner(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
t.Skip("https://github.com/coder/internal/issues/98")
|
|
||||||
|
|
||||||
t.Run("OK", func(t *testing.T) {
|
t.Run("OK", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@ -43,14 +43,16 @@ func Test_Runner(t *testing.T) {
|
|||||||
|
|
||||||
logs := bytes.NewBuffer(nil)
|
logs := bytes.NewBuffer(nil)
|
||||||
err := runner.Run(ctx, "1", logs)
|
err := runner.Run(ctx, "1", logs)
|
||||||
logStr := logs.String()
|
|
||||||
t.Log("Runner logs:\n\n" + logStr)
|
|
||||||
require.NoError(t, err)
|
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
|
// 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
|
// 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) {
|
t.Run("NoLogOutput", func(t *testing.T) {
|
||||||
@ -71,11 +73,12 @@ func Test_Runner(t *testing.T) {
|
|||||||
|
|
||||||
logs := bytes.NewBuffer(nil)
|
logs := bytes.NewBuffer(nil)
|
||||||
err := runner.Run(ctx, "1", logs)
|
err := runner.Run(ctx, "1", logs)
|
||||||
logStr := logs.String()
|
|
||||||
t.Log("Runner logs:\n\n" + logStr)
|
|
||||||
require.NoError(t, err)
|
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) {
|
t.Run("Timeout", func(t *testing.T) {
|
||||||
@ -199,8 +202,7 @@ func Test_Runner(t *testing.T) {
|
|||||||
Init: workspacesdk.AgentReconnectingPTYInit{
|
Init: workspacesdk.AgentReconnectingPTYInit{
|
||||||
Command: "echo 'hello world'; sleep 1",
|
Command: "echo 'hello world'; sleep 1",
|
||||||
},
|
},
|
||||||
ExpectOutput: "hello world",
|
LogOutput: true,
|
||||||
LogOutput: false,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
||||||
@ -208,8 +210,10 @@ func Test_Runner(t *testing.T) {
|
|||||||
|
|
||||||
logs := bytes.NewBuffer(nil)
|
logs := bytes.NewBuffer(nil)
|
||||||
err := runner.Run(ctx, "1", logs)
|
err := runner.Run(ctx, "1", logs)
|
||||||
logStr := logs.String()
|
require.NoError(t, err)
|
||||||
t.Log("Runner logs:\n\n" + logStr)
|
|
||||||
|
tr := testutil.NewTerminalReader(t, logs)
|
||||||
|
err = tr.ReadUntilString(ctx, "hello world")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -223,8 +227,7 @@ func Test_Runner(t *testing.T) {
|
|||||||
Init: workspacesdk.AgentReconnectingPTYInit{
|
Init: workspacesdk.AgentReconnectingPTYInit{
|
||||||
Command: "echo 'hello world'; sleep 1",
|
Command: "echo 'hello world'; sleep 1",
|
||||||
},
|
},
|
||||||
ExpectOutput: "bello borld",
|
LogOutput: true,
|
||||||
LogOutput: false,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
|
||||||
@ -232,10 +235,12 @@ func Test_Runner(t *testing.T) {
|
|||||||
|
|
||||||
logs := bytes.NewBuffer(nil)
|
logs := bytes.NewBuffer(nil)
|
||||||
err := runner.Run(ctx, "1", logs)
|
err := runner.Run(ctx, "1", logs)
|
||||||
logStr := logs.String()
|
require.NoError(t, err)
|
||||||
t.Log("Runner logs:\n\n" + logStr)
|
|
||||||
|
tr := testutil.NewTerminalReader(t, logs)
|
||||||
|
err = tr.ReadUntilString(ctx, "bello borld")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.ErrorContains(t, err, `expected string "bello borld" not found`)
|
require.ErrorIs(t, err, io.EOF)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user