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 }