Skip to content

Commit 2564f9c

Browse files
authored
test: scaletest/reconnectingpty: use TerminalReader (#15079)
Fixes: coder/internal#98
1 parent 687b4dd commit 2564f9c

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

scaletest/reconnectingpty/run_test.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package reconnectingpty_test
33
import (
44
"bytes"
55
"context"
6+
"io"
67
"testing"
78
"time"
89

@@ -22,7 +23,6 @@ import (
2223

2324
func Test_Runner(t *testing.T) {
2425
t.Parallel()
25-
t.Skip("https://github.com/coder/internal/issues/98")
2626

2727
t.Run("OK", func(t *testing.T) {
2828
t.Parallel()
@@ -43,14 +43,16 @@ func Test_Runner(t *testing.T) {
4343

4444
logs := bytes.NewBuffer(nil)
4545
err := runner.Run(ctx, "1", logs)
46-
logStr := logs.String()
47-
t.Log("Runner logs:\n\n" + logStr)
4846
require.NoError(t, err)
4947

50-
require.Contains(t, logStr, "Output:")
48+
tr := testutil.NewTerminalReader(t, logs)
49+
err = tr.ReadUntilString(ctx, "Output:")
50+
require.NoError(t, err)
51+
5152
// OSX: Output:\n\thello world\n
5253
// 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
53-
require.Contains(t, logStr, "hello world\n")
54+
err = tr.ReadUntilString(ctx, "hello world")
55+
require.NoError(t, err)
5456
})
5557

5658
t.Run("NoLogOutput", func(t *testing.T) {
@@ -71,11 +73,12 @@ func Test_Runner(t *testing.T) {
7173

7274
logs := bytes.NewBuffer(nil)
7375
err := runner.Run(ctx, "1", logs)
74-
logStr := logs.String()
75-
t.Log("Runner logs:\n\n" + logStr)
7676
require.NoError(t, err)
7777

78-
require.NotContains(t, logStr, "Output:")
78+
tr := testutil.NewTerminalReader(t, logs)
79+
err = tr.ReadUntilString(ctx, "Output:")
80+
require.Error(t, err)
81+
require.ErrorIs(t, err, io.EOF)
7982
})
8083

8184
t.Run("Timeout", func(t *testing.T) {
@@ -199,17 +202,18 @@ func Test_Runner(t *testing.T) {
199202
Init: workspacesdk.AgentReconnectingPTYInit{
200203
Command: "echo 'hello world'; sleep 1",
201204
},
202-
ExpectOutput: "hello world",
203-
LogOutput: false,
205+
LogOutput: true,
204206
})
205207

206208
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
207209
defer cancel()
208210

209211
logs := bytes.NewBuffer(nil)
210212
err := runner.Run(ctx, "1", logs)
211-
logStr := logs.String()
212-
t.Log("Runner logs:\n\n" + logStr)
213+
require.NoError(t, err)
214+
215+
tr := testutil.NewTerminalReader(t, logs)
216+
err = tr.ReadUntilString(ctx, "hello world")
213217
require.NoError(t, err)
214218
})
215219

@@ -223,19 +227,20 @@ func Test_Runner(t *testing.T) {
223227
Init: workspacesdk.AgentReconnectingPTYInit{
224228
Command: "echo 'hello world'; sleep 1",
225229
},
226-
ExpectOutput: "bello borld",
227-
LogOutput: false,
230+
LogOutput: true,
228231
})
229232

230233
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitSuperLong)
231234
defer cancel()
232235

233236
logs := bytes.NewBuffer(nil)
234237
err := runner.Run(ctx, "1", logs)
235-
logStr := logs.String()
236-
t.Log("Runner logs:\n\n" + logStr)
238+
require.NoError(t, err)
239+
240+
tr := testutil.NewTerminalReader(t, logs)
241+
err = tr.ReadUntilString(ctx, "bello borld")
237242
require.Error(t, err)
238-
require.ErrorContains(t, err, `expected string "bello borld" not found`)
243+
require.ErrorIs(t, err, io.EOF)
239244
})
240245
})
241246
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy