From fb37e0b7ca0687ac4302d35e2b3dd6506bd5e384 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Tue, 28 May 2013 12:55:11 -0700 Subject: [PATCH] use a smaller poll duration for faster test runs --- tail.go | 5 +++++ tail_test.go | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tail.go b/tail.go index 8e8a71a..e46bddd 100644 --- a/tail.go +++ b/tail.go @@ -102,6 +102,9 @@ func (tail *Tail) reopen() error { if err != nil { if os.IsNotExist(err) { log.Printf("Waiting for %s to appear...", tail.Filename) + // XXX: potential race condition here, as the file + // could have been created right after out IsNotExist + // check above. this will lead to blocking here forever. err := tail.watcher.BlockUntilExists() if err != nil { return fmt.Errorf("Failed to detect creation of %s: %s", tail.Filename, err) @@ -187,6 +190,7 @@ func (tail *Tail) tailFileSync() { if !ok { changes = nil // XXX: how to kill changes' goroutine? + log.Println("Changes channel is closed.") // File got deleted/renamed if tail.ReOpen { // TODO: no logging in a library? @@ -208,6 +212,7 @@ func (tail *Tail) tailFileSync() { } } case <-tail.Dying(): + log.Println("Dying..") tail.close() return } diff --git a/tail_test.go b/tail_test.go index 57cec46..b10ff9e 100644 --- a/tail_test.go +++ b/tail_test.go @@ -14,6 +14,7 @@ import ( ) func init() { + // Clear the temporary test directory err := os.RemoveAll(".test") if err != nil { panic(err) @@ -172,7 +173,7 @@ func _TestReSeek(_t *testing.T, poll bool) { // Delete after a reasonable delay, to give tail sufficient time // to read all lines. <-time.After(100 * time.Millisecond) - // XXX t.RemoveFile("test.txt") + t.RemoveFile("test.txt") println("Stopping...") tail.Stop() @@ -204,6 +205,10 @@ func NewTailTest(name string, t *testing.T) TailTest { if err != nil { tt.Fatal(err) } + + // Use a smaller poll duration for faster test runs. + POLL_DURATION = 25 * time.Millisecond + return tt }