veyron/runtimes/google/lib/follow: Fix flaky tests.

Specifics:
 - use unique temporary files so that concurrent runs do not interfere.
 - increase timeout in tests of the stat-based reader.

Change-Id: Icf768de5e1897d623d20e28df5a656503e24a1b5
diff --git a/runtimes/google/lib/follow/notify_reader_test.go b/runtimes/google/lib/follow/notify_reader_test.go
index 04f8827..380f6ce 100644
--- a/runtimes/google/lib/follow/notify_reader_test.go
+++ b/runtimes/google/lib/follow/notify_reader_test.go
@@ -3,6 +3,7 @@
 package follow
 
 import (
+	"io/ioutil"
 	"os"
 	"testing"
 	"time"
@@ -10,14 +11,13 @@
 
 // TestNotifyReadPartial tests partial reads with the fsnotify-based fsReader
 func TestNotifyReadPartial(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.reader.notify.partial"
-
 	// Create the test file.
-	testfile, err := os.Create(testFileName)
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.reader.notify.partial")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	testfile.Close()
+	testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	// Create the fsnotify-based fsWatcher.
@@ -34,14 +34,13 @@
 
 // TestNotifyReadFull tests full reads with the fsnotify-based fsReader
 func TestNotifyReadFull(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.reader.notify.full"
-
 	// Create the test file.
-	testfile, err := os.Create(testFileName)
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.reader.notify.full")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	testfile.Close()
+	testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	// Create the fsnotify-based fsWatcher.
@@ -58,14 +57,13 @@
 
 // TestNotifyClose tests close with the fsnotify-based fsReader
 func TestNotifyClose(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.reader.notify.close"
-
 	// Create the test file.
-	testfile, err := os.Create(testFileName)
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.reader.notify.close")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	testfile.Close()
+	testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	// Create the fsnotify-based fsWatcher.
diff --git a/runtimes/google/lib/follow/notify_watcher_test.go b/runtimes/google/lib/follow/notify_watcher_test.go
index 058f5a1..8ee84a5 100644
--- a/runtimes/google/lib/follow/notify_watcher_test.go
+++ b/runtimes/google/lib/follow/notify_watcher_test.go
@@ -3,18 +3,20 @@
 package follow
 
 import (
+	"io/ioutil"
 	"os"
 	"testing"
 	"time"
 )
 
 func TestModificationNotify(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.modification.notify"
-	testfile, err := os.Create(testFileName)
+	// Create the test file.
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.modification.notify")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	defer testfile.Close()
+	defer testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	watcher, err := newFSNotifyWatcher(testFileName)
@@ -22,7 +24,7 @@
 		t.Fatalf("newCustomFSWatcer() failed: %v", err)
 	}
 	timeout := time.Second
-	if err := testModification(testfile, watcher, timeout); err != nil {
+	if err := testModification(testFile, watcher, timeout); err != nil {
 		t.Fatalf("testModification() failed: %v", err)
 	}
 }
diff --git a/runtimes/google/lib/follow/stat_reader_test.go b/runtimes/google/lib/follow/stat_reader_test.go
index c67e8b7..21adb53 100644
--- a/runtimes/google/lib/follow/stat_reader_test.go
+++ b/runtimes/google/lib/follow/stat_reader_test.go
@@ -1,6 +1,7 @@
 package follow
 
 import (
+	"io/ioutil"
 	"os"
 	"testing"
 	"time"
@@ -8,14 +9,13 @@
 
 // TestStatReadPartial tests partial reads with the os.Stat()-based fsReader
 func TestStatReadPartial(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.reader.stat.partial"
-
 	// Create the test file.
-	testfile, err := os.Create(testFileName)
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.reader.stat.partial")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	testfile.Close()
+	testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	// Create the os.Stat()-based fsWatcher.
@@ -26,7 +26,7 @@
 		t.Fatalf("newCustomFSWatcher() failed: %v", err)
 	}
 
-	timeout := 100 * time.Millisecond
+	timeout := time.Second
 	if err := testReadPartial(testFileName, watcher, timeout); err != nil {
 		t.Fatalf("testReadPartial() failed: %v", err)
 	}
@@ -34,14 +34,13 @@
 
 // TestStatReadFull tests full reads with the os.Stat()-based fsReader
 func TestStatReadFull(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.reader.stat.full"
-
 	// Create the test file.
-	testfile, err := os.Create(testFileName)
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.reader.stat.full")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	testfile.Close()
+	testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	// Create the os.Stat()-based fsWatcher.
@@ -52,7 +51,7 @@
 		t.Fatalf("newCustomFSWatcher() failed: %v", err)
 	}
 
-	timeout := 100 * time.Millisecond
+	timeout := time.Second
 	if err := testReadFull(testFileName, watcher, timeout); err != nil {
 		t.Fatalf("testReadFull() failed: %v", err)
 	}
@@ -60,14 +59,13 @@
 
 // TestStatClose tests close with the os.Stat()-based fsReader
 func TestStatClose(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.reader.stat.close"
-
 	// Create the test file.
-	testfile, err := os.Create(testFileName)
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.reader.stat.close")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	testfile.Close()
+	testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	// Create the os.Stat()-based fsWatcher.
@@ -78,7 +76,7 @@
 		t.Fatalf("newCustomFSWatcher() failed: %v", err)
 	}
 
-	timeout := 100 * time.Millisecond
+	timeout := time.Second
 	if err := testClose(testFileName, watcher, timeout); err != nil {
 		t.Fatalf("testClose() failed: %v", err)
 	}
diff --git a/runtimes/google/lib/follow/stat_watcher_test.go b/runtimes/google/lib/follow/stat_watcher_test.go
index 5c12f00..67d14e8 100644
--- a/runtimes/google/lib/follow/stat_watcher_test.go
+++ b/runtimes/google/lib/follow/stat_watcher_test.go
@@ -1,18 +1,20 @@
 package follow
 
 import (
+	"io/ioutil"
 	"os"
 	"testing"
 	"time"
 )
 
 func TestModificationStat(t *testing.T) {
-	testFileName := os.TempDir() + "/follow.modification.stat"
-	testfile, err := os.Create(testFileName)
+	// Create the test file.
+	testFile, err := ioutil.TempFile(os.TempDir(), "follow.modification.stat")
 	if err != nil {
-		t.Fatalf("os.Create() failed: %v", err)
+		t.Fatalf("ioutil.TempFile() failed: %v", err)
 	}
-	defer testfile.Close()
+	defer testFile.Close()
+	testFileName := testFile.Name()
 	defer os.Remove(testFileName)
 
 	minSleep := 10 * time.Millisecond
@@ -22,7 +24,7 @@
 		t.Fatalf("newCustomFSWatcher() failed : %v", err)
 	}
 	timeout := 100 * time.Millisecond
-	if err := testModification(testfile, watcher, timeout); err != nil {
+	if err := testModification(testFile, watcher, timeout); err != nil {
 		t.Fatalf("testModification() failed: %v", err)
 	}
 }