Skip to content

Commit

Permalink
Fix flaky TestRunnerServiceServerExecute_WithInput/ContinuousInput
Browse files Browse the repository at this point in the history
  • Loading branch information
adambabik committed Jun 6, 2024
1 parent 8dbe07f commit d977502
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/runnerv2service/service_execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"
"testing/fstest"
"time"
"unicode"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -674,12 +675,15 @@ func TestRunnerServiceServerExecute_WithInput(t *testing.T) {
result := <-execResult

assert.NoError(t, result.Err)
expected := "a\r\nb\r\nc\r\nd\r\nA\r\nB\r\nC\r\nD\r\n"
// On macOS, the ctrl+d (EOT) character followed by two backspaces is collected.
// On Linux, in the CI, this does not occur.
got := string(bytes.ReplaceAll(result.Stdout, []byte("^D\b\b"), nil))
assert.Equal(t, expected, got)
assert.EqualValues(t, 0, result.ExitCode)
// Validate the output by asserting that lowercase letters precede uppercase letters.
for _, c := range "abcd" {
idxLower := bytes.IndexRune(result.Stdout, c)
idxUpper := bytes.IndexRune(result.Stdout, unicode.ToUpper(c))
assert.Greater(t, idxLower, -1)
assert.Greater(t, idxUpper, -1)
assert.True(t, idxUpper > idxLower)
}
})

t.Run("SimulateCtrlC", func(t *testing.T) {
Expand Down

0 comments on commit d977502

Please sign in to comment.