Skip to content
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

chore: Add (skipped) ptytest test that hangs on Intel Mac (and Windows) #1629

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions pty/ptytest/ptytest_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package ptytest_test

import (
"fmt"
"runtime"
"strings"
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

"github.com/coder/coder/pty/ptytest"
)

Expand All @@ -15,4 +21,41 @@ func TestPtytest(t *testing.T) {
pty.ExpectMatch("write")
pty.WriteLine("read")
})

t.Run("Cobra ptytest should not hang when output is not consumed", func(t *testing.T) {
t.Parallel()

tests := []struct {
name string
output string
isPlatformBug bool // See https://github.com/coder/coder/issues/2122 for more info.
}{
{name: "1024 is safe (does not exceed macOS buffer)", output: strings.Repeat(".", 1024)},
{name: "1025 exceeds macOS buffer (must not hang)", output: strings.Repeat(".", 1025), isPlatformBug: true},
{name: "10241 large output", output: strings.Repeat(".", 10241), isPlatformBug: true}, // 1024 * 10 + 1
}
for _, tt := range tests {
tt := tt
// nolint:paralleltest // Avoid parallel test to more easily identify the issue.
t.Run(tt.name, func(t *testing.T) {
if tt.isPlatformBug && (runtime.GOOS == "darwin" || runtime.GOOS == "windows") {
t.Skip("This test hangs on macOS and Windows, see https://github.com/coder/coder/issues/2122")
}
mafredri marked this conversation as resolved.
Show resolved Hide resolved

cmd := cobra.Command{
Use: "test",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Fprint(cmd.OutOrStdout(), tt.output)
return nil
},
}

pty := ptytest.New(t)
cmd.SetIn(pty.Input())
cmd.SetOut(pty.Output())
err := cmd.Execute()
require.NoError(t, err)
})
}
})
}