From bcfe176594fcd7dbab1d42e7a9b8ccf723f9bea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 4 Jun 2021 20:06:21 +0200 Subject: [PATCH] Fix flaky editor test There was a race condition wherein the test didn't wait enough time for the prompt to get rendered before testing the terminal output. --- pkg/surveyext/editor_test.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/surveyext/editor_test.go b/pkg/surveyext/editor_test.go index 03ad27989..c189c641b 100644 --- a/pkg/surveyext/editor_test.go +++ b/pkg/surveyext/editor_test.go @@ -59,8 +59,15 @@ func Test_GhEditor_Prompt(t *testing.T) { errc <- err }() - time.Sleep(5 * time.Millisecond) + for { + time.Sleep(time.Millisecond) + if strings.Contains(out.String(), "Body") { + break + } + } + assert.Equal(t, "\x1b[0G\x1b[2K\x1b[0;1;92m? \x1b[0m\x1b[0;1;99mBody \x1b[0m\x1b[0;36m[(e) to launch false, enter to skip] \x1b[0m\x1b[?25l", out.String()) + out.Reset() fmt.Fprint(pty, "\n") // send Enter key err = <-errc @@ -126,7 +133,12 @@ func (f *teeWriter) Write(p []byte) (n int, err error) { func (f *teeWriter) String() string { f.mu.Lock() s := f.buf.String() - f.buf.Reset() f.mu.Unlock() return s } + +func (f *teeWriter) Reset() { + f.mu.Lock() + f.buf.Reset() + f.mu.Unlock() +}