ui/termstatus: fix race condition in StdioWrapper

This commit is contained in:
Michael Eischer
2025-03-23 20:04:45 +01:00
parent 1221453d08
commit ec19d67512
3 changed files with 42 additions and 0 deletions

View File

@@ -1,10 +1,13 @@
package termstatus
import (
"context"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
rtest "github.com/restic/restic/internal/test"
"golang.org/x/sync/errgroup"
)
func TestStdioWrapper(t *testing.T) {
@@ -82,3 +85,18 @@ func TestStdioWrapper(t *testing.T) {
})
}
}
func TestStdioWrapperConcurrentWrites(t *testing.T) {
// tests for race conditions when run with `go test -race ./internal/ui/termstatus`
w := newLineWriter(func(_ string) {})
wg, _ := errgroup.WithContext(context.TODO())
for range 5 {
wg.Go(func() error {
_, err := w.Write([]byte("test\n"))
return err
})
}
rtest.OK(t, wg.Wait())
rtest.OK(t, w.Close())
}