diff options
author | Russ Cox <rsc@golang.org> | 2014-09-18 14:48:47 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-09-18 14:48:47 -0400 |
commit | 433566655a72738d3f2f700c4134226a88e6293d (patch) | |
tree | 0d1a03dd0ef67c23c76a33b275885bff0ada7f37 /src/os/os_test.go | |
parent | 798fe2075f9195866b3a8ea54e259f82bde116bf (diff) | |
download | go-433566655a72738d3f2f700c4134226a88e6293d.tar.gz |
os: avoid error result when dir is removed out from under RemoveAll
Fixes issue 7776.
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews, r
https://codereview.appspot.com/145860043
Diffstat (limited to 'src/os/os_test.go')
-rw-r--r-- | src/os/os_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/os/os_test.go b/src/os/os_test.go index 0224c9b01..7a2849741 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -18,6 +18,7 @@ import ( "runtime" "sort" "strings" + "sync" "syscall" "testing" "text/template" @@ -1403,3 +1404,44 @@ func TestNilFileMethods(t *testing.T) { } } } + +func mkdirTree(t *testing.T, root string, level, max int) { + if level >= max { + return + } + level++ + for i := 'a'; i < 'c'; i++ { + dir := filepath.Join(root, string(i)) + if err := Mkdir(dir, 0700); err != nil { + t.Fatal(err) + } + mkdirTree(t, dir, level, max) + } +} + +// Test that simultaneous RemoveAll do not report an error. +// As long as it gets removed, we should be happy. +func TestRemoveAllRace(t *testing.T) { + n := runtime.GOMAXPROCS(16) + defer runtime.GOMAXPROCS(n) + root, err := ioutil.TempDir("", "issue") + if err != nil { + t.Fatal(err) + } + mkdirTree(t, root, 1, 6) + hold := make(chan struct{}) + var wg sync.WaitGroup + for i := 0; i < 4; i++ { + wg.Add(1) + go func() { + defer wg.Done() + <-hold + err := RemoveAll(root) + if err != nil { + t.Errorf("unexpected error: %T, %q", err, err) + } + }() + } + close(hold) // let workers race to remove root + wg.Wait() +} |