Skip to content

Commit

Permalink
testing/fstest,os: clarify racy behavior of TestFS
Browse files Browse the repository at this point in the history
The testing.TestFS function assumes that the file system it's testing
doesn't change under it. Clarify this in the documentation and fix the
use of os.TestDirFS that's currently susceptible to this race.

Fixes #42637.

Change-Id: Ia7792380726177f8953d150ee87381b66cb01cb3
Reviewed-on: https://go-review.googlesource.com/c/go/+/282452
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
  • Loading branch information
aclements committed Jan 8, 2021
1 parent 32afcc9 commit 0c5afc4
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/os/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ func TestOpenFileKeepsPermissions(t *testing.T) {
}

func TestDirFS(t *testing.T) {
if err := fstest.TestFS(DirFS("./signal"), "signal.go", "internal/pty/pty.go"); err != nil {
if err := fstest.TestFS(DirFS("./testdata/dirfs"), "a", "b", "dir/x"); err != nil {
t.Fatal(err)
}
}
Expand Down
Empty file added src/os/testdata/dirfs/a
Empty file.
Empty file added src/os/testdata/dirfs/b
Empty file.
Empty file added src/os/testdata/dirfs/dir/x
Empty file.
1 change: 1 addition & 0 deletions src/testing/fstest/testfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
// It also checks that the file system contains at least the expected files.
// As a special case, if no expected files are listed, fsys must be empty.
// Otherwise, fsys must only contain at least the listed files: it can also contain others.
// The contents of fsys must not change concurrently with TestFS.
//
// If TestFS finds any misbehaviors, it returns an error reporting all of them.
// The error text spans multiple lines, one per detected misbehavior.
Expand Down

0 comments on commit 0c5afc4

Please sign in to comment.