From 4d53934eb027bae36e09a07f69bd4a7412c1eb58 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 25 Jul 2022 18:42:20 +0300 Subject: [PATCH] fix: (Re-)enable TestPasswordTerminalState test (#3169) --- cli/cliui/prompt_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cli/cliui/prompt_test.go b/cli/cliui/prompt_test.go index d80b964e51..eefc6ab4c8 100644 --- a/cli/cliui/prompt_test.go +++ b/cli/cliui/prompt_test.go @@ -165,9 +165,6 @@ func newPrompt(ptty *ptytest.PTY, opts cliui.PromptOptions, cmdOpt func(cmd *cob } func TestPasswordTerminalState(t *testing.T) { - // TODO: fix this test so that it runs reliably - t.Skip() - if os.Getenv("TEST_SUBPROCESS") == "1" { passwordHelper() return @@ -192,20 +189,21 @@ func TestPasswordTerminalState(t *testing.T) { defer process.Kill() ptty.ExpectMatch("Password: ") - time.Sleep(100 * time.Millisecond) // wait for child process to turn off echo and start reading input - echo, err := ptyWithFlags.EchoEnabled() - require.NoError(t, err) - require.False(t, echo, "echo is on while reading password") + require.Eventually(t, func() bool { + echo, err := ptyWithFlags.EchoEnabled() + return err == nil && !echo + }, 5*time.Second, 50*time.Millisecond, "echo is on while reading password") err = process.Signal(os.Interrupt) require.NoError(t, err) _, err = process.Wait() require.NoError(t, err) - echo, err = ptyWithFlags.EchoEnabled() - require.NoError(t, err) - require.True(t, echo, "echo is off after reading password") + require.Eventually(t, func() bool { + echo, err := ptyWithFlags.EchoEnabled() + return err == nil && echo + }, 5*time.Second, 50*time.Millisecond, "echo is off after reading password") } // nolint:unused