fix: Increase ptytest buffer to resolve flake (#1141)

From investigating the following run:
https://github.com/coder/coder/runs/6156348454?check_suite_focus=true

It's believed that the cause is data being discarded due to the buffer
filling up. This _might_ fix it, but not entirely sure.
This commit is contained in:
Kyle Carberry 2022-04-25 12:14:16 -05:00 committed by GitHub
parent 66d45f391e
commit 185d97a65b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -76,6 +76,11 @@ func TestAgent(t *testing.T) {
session.Stdin = ptty.Input()
err = session.Start(command)
require.NoError(t, err)
caret := "$"
if runtime.GOOS == "windows" {
caret = ">"
}
ptty.ExpectMatch(caret)
ptty.WriteLine("echo test")
ptty.ExpectMatch("test")
ptty.WriteLine("exit")

View File

@ -3,6 +3,7 @@ package ptytest
import (
"bufio"
"bytes"
"context"
"io"
"os"
"os/exec"
@ -10,6 +11,7 @@ import (
"runtime"
"strings"
"testing"
"time"
"unicode/utf8"
"github.com/stretchr/testify/require"
@ -76,6 +78,19 @@ func (p *PTY) ExpectMatch(str string) string {
var buffer bytes.Buffer
multiWriter := io.MultiWriter(&buffer, p.outputWriter)
runeWriter := bufio.NewWriterSize(multiWriter, utf8.UTFMax)
complete, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
go func() {
timer := time.NewTimer(10 * time.Second)
defer timer.Stop()
select {
case <-complete.Done():
return
case <-timer.C:
}
_ = p.Close()
p.t.Errorf("match exceeded deadline: wanted %q; got %q", str, buffer.String())
}()
for {
var r rune
r, _, err := p.runeReader.ReadRune()