2018-08-16 20:53:47 +02:00
|
|
|
package watch
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2019-05-14 21:05:03 +02:00
|
|
|
"runtime"
|
2018-08-16 20:53:47 +02:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2018-12-20 00:56:40 +01:00
|
|
|
|
|
|
|
"github.com/windmilleng/tilt/internal/testutils/tempdir"
|
2018-08-16 20:53:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Each implementation of the notify interface should have the same basic
|
|
|
|
// behavior.
|
|
|
|
|
|
|
|
func TestNoEvents(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
f.assertEvents()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEventOrdering(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
|
|
|
count := 8
|
|
|
|
dirs := make([]string, count)
|
|
|
|
for i, _ := range dirs {
|
2018-12-20 00:56:40 +01:00
|
|
|
dir := f.TempDir("watched")
|
|
|
|
dirs[i] = dir
|
|
|
|
err := f.notify.Add(dir)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
|
|
|
|
2018-08-22 21:33:06 +02:00
|
|
|
var expected []string
|
2018-08-16 20:53:47 +02:00
|
|
|
for i, dir := range dirs {
|
|
|
|
base := fmt.Sprintf("%d.txt", i)
|
|
|
|
p := filepath.Join(dir, base)
|
|
|
|
err := ioutil.WriteFile(p, []byte(base), os.FileMode(0777))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-22 21:33:06 +02:00
|
|
|
expected = append(expected, filepath.Join(dir, base))
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
f.assertEvents(expected...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWatchesAreRecursive(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
root := f.TempDir("root")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
// add a sub directory
|
2018-12-20 00:56:40 +01:00
|
|
|
subPath := filepath.Join(root, "sub")
|
|
|
|
f.MkdirAll(subPath)
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
// watch parent
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Add(root)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
|
|
|
// change sub directory
|
|
|
|
changeFilePath := filepath.Join(subPath, "change")
|
|
|
|
_, err = os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(changeFilePath)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
root := f.TempDir("root")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
// watch parent
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Add(root)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
2018-12-20 00:56:40 +01:00
|
|
|
|
2018-08-16 20:53:47 +02:00
|
|
|
// add a sub directory
|
2018-12-20 00:56:40 +01:00
|
|
|
subPath := filepath.Join(root, "sub")
|
|
|
|
f.MkdirAll(subPath)
|
|
|
|
|
2018-08-16 20:53:47 +02:00
|
|
|
// change something inside sub directory
|
|
|
|
changeFilePath := filepath.Join(subPath, "change")
|
|
|
|
_, err = os.OpenFile(changeFilePath, os.O_RDONLY|os.O_CREATE, 0666)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(subPath, changeFilePath)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestWatchNonExistentPath(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
root := f.TempDir("root")
|
|
|
|
path := filepath.Join(root, "change")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Add(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-23 19:24:47 +02:00
|
|
|
|
|
|
|
f.fsync()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
d1 := "hello\ngo\n"
|
|
|
|
f.WriteFile(path, d1)
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
2019-03-22 21:17:12 +01:00
|
|
|
func TestWatchNonExistentPathDoesNotFireSiblingEvent(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
|
|
|
root := f.TempDir("root")
|
|
|
|
watchedFile := filepath.Join(root, "a.txt")
|
|
|
|
unwatchedSibling := filepath.Join(root, "b.txt")
|
|
|
|
|
|
|
|
err := f.notify.Add(watchedFile)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f.fsync()
|
|
|
|
|
|
|
|
d1 := "hello\ngo\n"
|
|
|
|
f.WriteFile(unwatchedSibling, d1)
|
|
|
|
f.assertEvents()
|
|
|
|
}
|
|
|
|
|
2018-08-16 20:53:47 +02:00
|
|
|
func TestRemove(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
root := f.TempDir("root")
|
|
|
|
path := filepath.Join(root, "change")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
d1 := "hello\ngo\n"
|
|
|
|
f.WriteFile(path, d1)
|
2018-08-16 20:53:47 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Add(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
|
|
|
err = os.Remove(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveAndAddBack(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
path := filepath.Join(f.watched, "change")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
d1 := []byte("hello\ngo\n")
|
2018-08-22 21:48:33 +02:00
|
|
|
err := ioutil.WriteFile(path, d1, 0644)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = f.notify.Add(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-22 21:48:33 +02:00
|
|
|
f.assertEvents(path)
|
|
|
|
|
2018-08-16 20:53:47 +02:00
|
|
|
err = os.Remove(path)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
f.events = nil
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(path, d1, 0644)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSingleFile(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
root := f.TempDir("root")
|
|
|
|
path := filepath.Join(root, "change")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
d1 := "hello\ngo\n"
|
|
|
|
f.WriteFile(path, d1)
|
2018-08-16 20:53:47 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Add(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-23 17:56:00 +02:00
|
|
|
f.fsync()
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
d2 := []byte("hello\nworld\n")
|
|
|
|
err = ioutil.WriteFile(path, d2, 0644)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-08-22 21:33:06 +02:00
|
|
|
f.assertEvents(path)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 21:59:46 +02:00
|
|
|
func TestWriteBrokenLink(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
link := filepath.Join(f.watched, "brokenLink")
|
|
|
|
missingFile := filepath.Join(f.watched, "missingFile")
|
2018-08-22 21:59:46 +02:00
|
|
|
err := os.Symlink(missingFile, link)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f.assertEvents(link)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWriteGoodLink(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
goodFile := filepath.Join(f.watched, "goodFile")
|
2018-08-22 21:59:46 +02:00
|
|
|
err := ioutil.WriteFile(goodFile, []byte("hello"), 0644)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
link := filepath.Join(f.watched, "goodFileSymlink")
|
2018-08-22 21:59:46 +02:00
|
|
|
err = os.Symlink(goodFile, link)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f.assertEvents(goodFile, link)
|
|
|
|
}
|
|
|
|
|
2018-09-14 23:13:36 +02:00
|
|
|
func TestWatchBrokenLink(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
|
|
|
newRoot, err := NewDir(t.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer newRoot.TearDown()
|
|
|
|
|
|
|
|
link := filepath.Join(newRoot.Path(), "brokenLink")
|
|
|
|
missingFile := filepath.Join(newRoot.Path(), "missingFile")
|
|
|
|
err = os.Symlink(missingFile, link)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = f.notify.Add(newRoot.Path())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Remove(link)
|
|
|
|
f.assertEvents(link)
|
|
|
|
}
|
|
|
|
|
2018-10-18 16:44:07 +02:00
|
|
|
func TestMoveAndReplace(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
root := f.TempDir("root")
|
|
|
|
file := filepath.Join(root, "myfile")
|
|
|
|
f.WriteFile(file, "hello")
|
2018-10-18 16:44:07 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Add(file)
|
2018-10-18 16:44:07 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
tmpFile := filepath.Join(root, ".myfile.swp")
|
|
|
|
f.WriteFile(tmpFile, "world")
|
2018-10-18 16:44:07 +02:00
|
|
|
|
|
|
|
err = os.Rename(tmpFile, file)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f.assertEvents(file)
|
|
|
|
}
|
|
|
|
|
2018-12-20 18:20:34 +01:00
|
|
|
func TestWatchBothDirAndFile(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
|
|
|
dir := f.JoinPath("foo")
|
|
|
|
fileA := f.JoinPath("foo", "a")
|
|
|
|
fileB := f.JoinPath("foo", "b")
|
|
|
|
f.WriteFile(fileA, "a")
|
|
|
|
f.WriteFile(fileB, "b")
|
|
|
|
|
|
|
|
f.watch(fileA)
|
|
|
|
f.watch(dir)
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
|
|
|
|
|
|
|
f.WriteFile(fileB, "b-new")
|
|
|
|
f.assertEvents(fileB)
|
|
|
|
}
|
|
|
|
|
2019-05-14 21:05:03 +02:00
|
|
|
func TestWatchNonexistentFileInNonexistentDirectoryCreatedSimultaneously(t *testing.T) {
|
2019-01-16 20:57:50 +01:00
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
|
|
|
root := f.JoinPath("root")
|
|
|
|
err := os.Mkdir(root, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
file := f.JoinPath("root", "parent", "a")
|
|
|
|
|
|
|
|
f.watch(file)
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
|
|
|
f.WriteFile(file, "hello")
|
2019-03-22 21:17:12 +01:00
|
|
|
f.assertEvents(file)
|
2019-01-16 20:57:50 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 21:05:03 +02:00
|
|
|
func TestWatchNonexistentDirectory(t *testing.T) {
|
|
|
|
f := newNotifyFixture(t)
|
|
|
|
defer f.tearDown()
|
|
|
|
|
|
|
|
root := f.JoinPath("root")
|
|
|
|
err := os.Mkdir(root, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
parent := f.JoinPath("parent")
|
|
|
|
file := f.JoinPath("parent", "a")
|
|
|
|
|
|
|
|
f.watch(parent)
|
|
|
|
f.fsync()
|
|
|
|
f.events = nil
|
|
|
|
|
|
|
|
err = os.Mkdir(parent, 0777)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
// for directories that were the root of an Add, we don't report creation, cf. watcher_darwin.go
|
|
|
|
f.assertEvents()
|
|
|
|
} else {
|
|
|
|
f.assertEvents(parent)
|
|
|
|
}
|
|
|
|
f.WriteFile(file, "hello")
|
|
|
|
|
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
// mac doesn't return the dir change as part of file creation
|
|
|
|
f.assertEvents(file)
|
|
|
|
} else {
|
|
|
|
f.assertEvents(parent, file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// doesn't work on linux
|
|
|
|
// func TestWatchNonexistentFileInNonexistentDirectory(t *testing.T) {
|
|
|
|
// f := newNotifyFixture(t)
|
|
|
|
// defer f.tearDown()
|
|
|
|
|
|
|
|
// root := f.JoinPath("root")
|
|
|
|
// err := os.Mkdir(root, 0777)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
|
|
|
// parent := f.JoinPath("parent")
|
|
|
|
// file := f.JoinPath("parent", "a")
|
|
|
|
|
|
|
|
// f.watch(file)
|
|
|
|
// f.assertEvents()
|
|
|
|
|
|
|
|
// err = os.Mkdir(parent, 0777)
|
|
|
|
// if err != nil {
|
|
|
|
// t.Fatal(err)
|
|
|
|
// }
|
|
|
|
|
|
|
|
// f.assertEvents()
|
|
|
|
// f.WriteFile(file, "hello")
|
|
|
|
// f.assertEvents(file)
|
|
|
|
// }
|
|
|
|
|
2018-08-16 20:53:47 +02:00
|
|
|
type notifyFixture struct {
|
2018-12-20 00:56:40 +01:00
|
|
|
*tempdir.TempDirFixture
|
2018-08-16 20:53:47 +02:00
|
|
|
notify Notify
|
2018-12-20 00:56:40 +01:00
|
|
|
watched string
|
2018-08-22 21:33:06 +02:00
|
|
|
events []FileEvent
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func newNotifyFixture(t *testing.T) *notifyFixture {
|
|
|
|
notify, err := NewWatcher()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
f := tempdir.NewTempDirFixture(t)
|
|
|
|
watched := f.TempDir("watched")
|
2018-08-16 20:53:47 +02:00
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
err = notify.Add(watched)
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return ¬ifyFixture{
|
2018-12-20 00:56:40 +01:00
|
|
|
TempDirFixture: f,
|
|
|
|
watched: watched,
|
|
|
|
notify: notify,
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 18:20:34 +01:00
|
|
|
func (f *notifyFixture) watch(path string) {
|
|
|
|
err := f.notify.Add(path)
|
|
|
|
if err != nil {
|
|
|
|
f.T().Fatalf("notify.Add: %s", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-22 21:33:06 +02:00
|
|
|
func (f *notifyFixture) assertEvents(expected ...string) {
|
|
|
|
f.fsync()
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
if len(f.events) != len(expected) {
|
2018-12-20 00:56:40 +01:00
|
|
|
f.T().Fatalf("Got %d events (expected %d): %v %v", len(f.events), len(expected), f.events, expected)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, actual := range f.events {
|
2018-08-22 21:33:06 +02:00
|
|
|
e := FileEvent{expected[i]}
|
|
|
|
if actual != e {
|
2018-12-20 00:56:40 +01:00
|
|
|
f.T().Fatalf("Got event %v (expected %v)", actual, e)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *notifyFixture) fsync() {
|
|
|
|
syncPathBase := fmt.Sprintf("sync-%d.txt", time.Now().UnixNano())
|
2018-12-20 00:56:40 +01:00
|
|
|
syncPath := filepath.Join(f.watched, syncPathBase)
|
|
|
|
anySyncPath := filepath.Join(f.watched, "sync-")
|
2018-08-16 20:53:47 +02:00
|
|
|
timeout := time.After(time.Second)
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
f.WriteFile(syncPath, fmt.Sprintf("%s", time.Now()))
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
F:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case err := <-f.notify.Errors():
|
2018-12-20 00:56:40 +01:00
|
|
|
f.T().Fatal(err)
|
2018-08-16 20:53:47 +02:00
|
|
|
|
|
|
|
case event := <-f.notify.Events():
|
2018-08-22 21:33:06 +02:00
|
|
|
if strings.Contains(event.Path, syncPath) {
|
2018-08-16 20:53:47 +02:00
|
|
|
break F
|
|
|
|
}
|
2018-08-22 21:33:06 +02:00
|
|
|
if strings.Contains(event.Path, anySyncPath) {
|
2018-08-16 20:53:47 +02:00
|
|
|
continue
|
|
|
|
}
|
2018-08-22 21:33:06 +02:00
|
|
|
|
|
|
|
// Don't bother tracking duplicate changes to the same path
|
|
|
|
// for testing.
|
|
|
|
if len(f.events) > 0 && f.events[len(f.events)-1].Path == event.Path {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-08-16 20:53:47 +02:00
|
|
|
f.events = append(f.events, event)
|
|
|
|
|
|
|
|
case <-timeout:
|
2018-12-20 00:56:40 +01:00
|
|
|
f.T().Fatalf("fsync: timeout")
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *notifyFixture) tearDown() {
|
2018-12-20 00:56:40 +01:00
|
|
|
err := f.notify.Close()
|
2018-08-16 20:53:47 +02:00
|
|
|
if err != nil {
|
2018-12-20 00:56:40 +01:00
|
|
|
f.T().Fatal(err)
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|
2018-12-20 00:56:40 +01:00
|
|
|
|
2019-05-14 21:05:03 +02:00
|
|
|
// drain channels from watcher
|
|
|
|
go func() {
|
|
|
|
for _ = range f.notify.Events() {
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
for _ = range f.notify.Errors() {
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-12-20 00:56:40 +01:00
|
|
|
f.TempDirFixture.TearDown()
|
2018-08-16 20:53:47 +02:00
|
|
|
}
|