Skip to content

Commit f9da263

Browse files
authored
test(cli): Fix portforward test timeouts (#7241)
1 parent f39e6a7 commit f9da263

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

cli/portforward_test.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ import (
2121
"github.com/coder/coder/testutil"
2222
)
2323

24-
//nolint:tparallel,paralleltest // Subtests require setup that must not be done in parallel.
25-
func TestPortForward(t *testing.T) {
26-
t.Run("None", func(t *testing.T) {
27-
t.Parallel()
24+
func TestPortForward_None(t *testing.T) {
25+
t.Parallel()
2826

29-
client := coderdtest.New(t, nil)
30-
_ = coderdtest.CreateFirstUser(t, client)
27+
client := coderdtest.New(t, nil)
28+
_ = coderdtest.CreateFirstUser(t, client)
3129

32-
inv, root := clitest.New(t, "port-forward", "blah")
33-
clitest.SetupConfig(t, client, root)
34-
pty := ptytest.New(t).Attach(inv)
35-
inv.Stderr = pty.Output()
30+
inv, root := clitest.New(t, "port-forward", "blah")
31+
clitest.SetupConfig(t, client, root)
32+
pty := ptytest.New(t).Attach(inv)
33+
inv.Stderr = pty.Output()
3634

37-
err := inv.Run()
38-
require.Error(t, err)
39-
require.ErrorContains(t, err, "no port-forwards")
35+
err := inv.Run()
36+
require.Error(t, err)
37+
require.ErrorContains(t, err, "no port-forwards")
4038

41-
// Check that the help was printed.
42-
pty.ExpectMatch("port-forward <workspace>")
43-
})
39+
// Check that the help was printed.
40+
pty.ExpectMatch("port-forward <workspace>")
41+
}
4442

43+
//nolint:tparallel,paralleltest // Subtests require setup that must not be done in parallel.
44+
func TestPortForward(t *testing.T) {
4545
cases := []struct {
4646
name string
4747
network string
@@ -134,13 +134,13 @@ func TestPortForward(t *testing.T) {
134134
inv.Stdin = pty.Input()
135135
inv.Stdout = pty.Output()
136136
inv.Stderr = pty.Output()
137-
ctx, cancel := context.WithCancel(context.Background())
137+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
138138
defer cancel()
139139
errC := make(chan error)
140140
go func() {
141141
errC <- inv.WithContext(ctx).Run()
142142
}()
143-
pty.ExpectMatch("Ready!")
143+
pty.ExpectMatchContext(ctx, "Ready!")
144144

145145
t.Parallel() // Port is reserved, enable parallel execution.
146146

@@ -181,13 +181,13 @@ func TestPortForward(t *testing.T) {
181181
inv.Stdin = pty.Input()
182182
inv.Stdout = pty.Output()
183183
inv.Stderr = pty.Output()
184-
ctx, cancel := context.WithCancel(context.Background())
184+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
185185
defer cancel()
186186
errC := make(chan error)
187187
go func() {
188188
errC <- inv.WithContext(ctx).Run()
189189
}()
190-
pty.ExpectMatch("Ready!")
190+
pty.ExpectMatchContext(ctx, "Ready!")
191191

192192
t.Parallel() // Port is reserved, enable parallel execution.
193193

@@ -234,13 +234,13 @@ func TestPortForward(t *testing.T) {
234234
clitest.SetupConfig(t, client, root)
235235
pty := ptytest.New(t).Attach(inv)
236236
inv.Stderr = pty.Output()
237-
ctx, cancel := context.WithCancel(context.Background())
237+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
238238
defer cancel()
239239
errC := make(chan error)
240240
go func() {
241241
errC <- inv.WithContext(ctx).Run()
242242
}()
243-
pty.ExpectMatch("Ready!")
243+
pty.ExpectMatchContext(ctx, "Ready!")
244244

245245
t.Parallel() // Port is reserved, enable parallel execution.
246246

0 commit comments

Comments
 (0)