From c3590b5c4cf49cfee3919032917467c6f24b34a2 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 May 2015 22:02:35 -0400 Subject: [PATCH] Fix validator_test hang on Solaris, Plan 9 On these platforms, the `done <- true` statement in during TearDown() was hanging, since the `watcher_unsupported.go` version was never draining the channel. Also took the opportunity to update the WatchForUpdates() signature to not return bool anymore. --- validator.go | 5 +---- watcher.go | 4 ++-- watcher_unsupported.go | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/validator.go b/validator.go index 3e0373a4..4e3fe671 100644 --- a/validator.go +++ b/validator.go @@ -21,13 +21,10 @@ func NewUserMap(usersFile string, done <-chan bool, onUpdate func()) *UserMap { atomic.StorePointer(&um.m, unsafe.Pointer(&m)) if usersFile != "" { log.Printf("using authenticated emails file %s", usersFile) - started := WatchForUpdates(usersFile, done, func() { + WatchForUpdates(usersFile, done, func() { um.LoadAuthenticatedEmailsFile() onUpdate() }) - if started { - log.Printf("watching %s for updates", usersFile) - } um.LoadAuthenticatedEmailsFile() } return um diff --git a/watcher.go b/watcher.go index fa8f03fa..c34058b1 100644 --- a/watcher.go +++ b/watcher.go @@ -30,7 +30,7 @@ func WaitForReplacement(filename string, op fsnotify.Op, } } -func WatchForUpdates(filename string, done <-chan bool, action func()) bool { +func WatchForUpdates(filename string, done <-chan bool, action func()) { filename = filepath.Clean(filename) watcher, err := fsnotify.NewWatcher() if err != nil { @@ -65,5 +65,5 @@ func WatchForUpdates(filename string, done <-chan bool, action func()) bool { if err = watcher.Add(filename); err != nil { log.Fatal("failed to add ", filename, " to watcher: ", err) } - return true + log.Printf("watching %s for updates", filename) } diff --git a/watcher_unsupported.go b/watcher_unsupported.go index d65c8632..937f49bb 100644 --- a/watcher_unsupported.go +++ b/watcher_unsupported.go @@ -6,7 +6,7 @@ import ( "log" ) -func WatchForUpdates(filename string, done <-chan bool, action func()) bool { +func WatchForUpdates(filename string, done <-chan bool, action func()) { log.Printf("file watching not implemented on this platform") - return false + go func() { <-done }() }