mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
ui/termstatus: fix race condition in StdioWrapper
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user