aboutsummaryrefslogtreecommitdiff
path: root/src/os/os_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/os_test.go')
-rw-r--r--src/os/os_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/os/os_test.go b/src/os/os_test.go
index 29f2e6d3b2..47f4163220 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -3468,6 +3468,34 @@ func TestWriteStringAlloc(t *testing.T) {
}
}
+// Test that it's OK to have parallel I/O and Close on a file.
+func TestFileIOCloseRace(t *testing.T) {
+ t.Parallel()
+ file, err := Create(filepath.Join(t.TempDir(), "test.txt"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var wg sync.WaitGroup
+ wg.Go(func() {
+ var tmp [100]byte
+ if _, err := file.Write(tmp[:]); err != nil && !errors.Is(err, ErrClosed) {
+ t.Error(err)
+ }
+ })
+ wg.Go(func() {
+ var tmp [100]byte
+ if _, err := file.Read(tmp[:]); err != nil && err != io.EOF && !errors.Is(err, ErrClosed) {
+ t.Error(err)
+ }
+ })
+ wg.Go(func() {
+ if err := file.Close(); err != nil {
+ t.Error(err)
+ }
+ })
+ wg.Wait()
+}
+
// Test that it's OK to have parallel I/O and Close on a pipe.
func TestPipeIOCloseRace(t *testing.T) {
// Skip on wasm, which doesn't have pipes.