fix: flaky prompt termination on reader close test

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
This commit is contained in:
Alano Terblanche 2024-03-21 10:53:30 +01:00
parent 2ae903e86c
commit d2ea5adfe4
No known key found for this signature in database
GPG Key ID: 0E8FACD1BA98DE27
1 changed files with 1 additions and 3 deletions

View File

@ -197,13 +197,11 @@ func TestPromptForConfirmation(t *testing.T) {
promptReader, promptWriter = io.Pipe() promptReader, promptWriter = io.Pipe()
wroteHook := make(chan struct{}, 1) wroteHook := make(chan struct{}, 1)
defer close(wroteHook)
promptOut := test.NewWriterWithHook(bufioWriter, func(p []byte) { promptOut := test.NewWriterWithHook(bufioWriter, func(p []byte) {
wroteHook <- struct{}{} wroteHook <- struct{}{}
}) })
result := make(chan promptResult, 1) result := make(chan promptResult, 1)
defer close(result)
go func() { go func() {
r, err := command.PromptForConfirmation(ctx, promptReader, promptOut, "") r, err := command.PromptForConfirmation(ctx, promptReader, promptOut, "")
result <- promptResult{r, err} result <- promptResult{r, err}
@ -216,7 +214,7 @@ func TestPromptForConfirmation(t *testing.T) {
assert.NilError(t, bufioWriter.Flush()) assert.NilError(t, bufioWriter.Flush())
assert.Equal(t, strings.TrimSpace(buf.String()), "Are you sure you want to proceed? [y/N]") assert.Equal(t, strings.TrimSpace(buf.String()), "Are you sure you want to proceed? [y/N]")
resultCtx, resultCancel := context.WithTimeout(ctx, 100*time.Millisecond) resultCtx, resultCancel := context.WithTimeout(ctx, 500*time.Millisecond)
defer resultCancel() defer resultCancel()
tc.f(t, resultCtx, result) tc.f(t, resultCtx, result)