mirror of
https://github.com/golang/go
synced 2024-11-19 07:54:43 -07:00
syscall: make TestFcntlFlock more robust
Avoid the use of constant absolute temp files in tests. This could produce flaky results, for example on multiuser development machines. Change-Id: Ia76157a0660fbe294bb31a46ded886cea5deec97 Reviewed-on: https://go-review.googlesource.com/40916 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
69182885d9
commit
16db1892d3
@ -78,12 +78,16 @@ func TestFcntlFlock(t *testing.T) {
|
||||
}
|
||||
if os.Getenv("GO_WANT_HELPER_PROCESS") == "" {
|
||||
// parent
|
||||
name := filepath.Join(os.TempDir(), "TestFcntlFlock")
|
||||
tempDir, err := ioutil.TempDir("", "TestFcntlFlock")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
name := filepath.Join(tempDir, "TestFcntlFlock")
|
||||
fd, err := syscall.Open(name, syscall.O_CREAT|syscall.O_RDWR|syscall.O_CLOEXEC, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Open failed: %v", err)
|
||||
}
|
||||
defer syscall.Unlink(name)
|
||||
defer os.RemoveAll(tempDir)
|
||||
defer syscall.Close(fd)
|
||||
if err := syscall.Ftruncate(fd, 1<<20); err != nil {
|
||||
t.Fatalf("Ftruncate(1<<20) failed: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user