From d9775023bd5771bbe0d277c59e89d6c24af95cf4 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Fri, 7 Jun 2024 00:46:35 +0200 Subject: [PATCH] Fix flaky TestRunnerServiceServerExecute_WithInput/ContinuousInput --- internal/runnerv2service/service_execute_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/runnerv2service/service_execute_test.go b/internal/runnerv2service/service_execute_test.go index 03342cf8..f8b18d60 100644 --- a/internal/runnerv2service/service_execute_test.go +++ b/internal/runnerv2service/service_execute_test.go @@ -10,6 +10,7 @@ import ( "testing" "testing/fstest" "time" + "unicode" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -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) {