From 16db1892d32bffdcc636665ba0325142b3c7ad72 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Mon, 17 Apr 2017 21:32:21 +0200 Subject: [PATCH] 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/syscall/syscall_unix_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/syscall/syscall_unix_test.go b/src/syscall/syscall_unix_test.go index 2f25d18bca9..b1fe78deba4 100644 --- a/src/syscall/syscall_unix_test.go +++ b/src/syscall/syscall_unix_test.go @@ -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)