Skip to content

test(cli): Fix portforward test timeouts #7241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions cli/portforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ import (
"github.com/coder/coder/testutil"
)

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

client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)
client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)

inv, root := clitest.New(t, "port-forward", "blah")
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
inv.Stderr = pty.Output()
inv, root := clitest.New(t, "port-forward", "blah")
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
inv.Stderr = pty.Output()

err := inv.Run()
require.Error(t, err)
require.ErrorContains(t, err, "no port-forwards")
err := inv.Run()
require.Error(t, err)
require.ErrorContains(t, err, "no port-forwards")

// Check that the help was printed.
pty.ExpectMatch("port-forward <workspace>")
})
// Check that the help was printed.
pty.ExpectMatch("port-forward <workspace>")
}

//nolint:tparallel,paralleltest // Subtests require setup that must not be done in parallel.
func TestPortForward(t *testing.T) {
cases := []struct {
name string
network string
Expand Down Expand Up @@ -134,13 +134,13 @@ func TestPortForward(t *testing.T) {
inv.Stdin = pty.Input()
inv.Stdout = pty.Output()
inv.Stderr = pty.Output()
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
errC := make(chan error)
go func() {
errC <- inv.WithContext(ctx).Run()
}()
pty.ExpectMatch("Ready!")
pty.ExpectMatchContext(ctx, "Ready!")

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

Expand Down Expand Up @@ -181,13 +181,13 @@ func TestPortForward(t *testing.T) {
inv.Stdin = pty.Input()
inv.Stdout = pty.Output()
inv.Stderr = pty.Output()
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
errC := make(chan error)
go func() {
errC <- inv.WithContext(ctx).Run()
}()
pty.ExpectMatch("Ready!")
pty.ExpectMatchContext(ctx, "Ready!")

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

Expand Down Expand Up @@ -234,13 +234,13 @@ func TestPortForward(t *testing.T) {
clitest.SetupConfig(t, client, root)
pty := ptytest.New(t).Attach(inv)
inv.Stderr = pty.Output()
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
errC := make(chan error)
go func() {
errC <- inv.WithContext(ctx).Run()
}()
pty.ExpectMatch("Ready!")
pty.ExpectMatchContext(ctx, "Ready!")

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

Expand Down