use a smaller poll duration for faster test runs
This commit is contained in:
parent
c90cd7b8db
commit
fb37e0b7ca
5
tail.go
5
tail.go
|
@ -102,6 +102,9 @@ func (tail *Tail) reopen() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Printf("Waiting for %s to appear...", tail.Filename)
|
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()
|
err := tail.watcher.BlockUntilExists()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to detect creation of %s: %s", tail.Filename, err)
|
return fmt.Errorf("Failed to detect creation of %s: %s", tail.Filename, err)
|
||||||
|
@ -187,6 +190,7 @@ func (tail *Tail) tailFileSync() {
|
||||||
if !ok {
|
if !ok {
|
||||||
changes = nil // XXX: how to kill changes' goroutine?
|
changes = nil // XXX: how to kill changes' goroutine?
|
||||||
|
|
||||||
|
log.Println("Changes channel is closed.")
|
||||||
// File got deleted/renamed
|
// File got deleted/renamed
|
||||||
if tail.ReOpen {
|
if tail.ReOpen {
|
||||||
// TODO: no logging in a library?
|
// TODO: no logging in a library?
|
||||||
|
@ -208,6 +212,7 @@ func (tail *Tail) tailFileSync() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case <-tail.Dying():
|
case <-tail.Dying():
|
||||||
|
log.Println("Dying..")
|
||||||
tail.close()
|
tail.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// Clear the temporary test directory
|
||||||
err := os.RemoveAll(".test")
|
err := os.RemoveAll(".test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -172,7 +173,7 @@ func _TestReSeek(_t *testing.T, poll bool) {
|
||||||
// Delete after a reasonable delay, to give tail sufficient time
|
// Delete after a reasonable delay, to give tail sufficient time
|
||||||
// to read all lines.
|
// to read all lines.
|
||||||
<-time.After(100 * time.Millisecond)
|
<-time.After(100 * time.Millisecond)
|
||||||
// XXX t.RemoveFile("test.txt")
|
t.RemoveFile("test.txt")
|
||||||
|
|
||||||
println("Stopping...")
|
println("Stopping...")
|
||||||
tail.Stop()
|
tail.Stop()
|
||||||
|
@ -204,6 +205,10 @@ func NewTailTest(name string, t *testing.T) TailTest {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tt.Fatal(err)
|
tt.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use a smaller poll duration for faster test runs.
|
||||||
|
POLL_DURATION = 25 * time.Millisecond
|
||||||
|
|
||||||
return tt
|
return tt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue