From 734bf58f78e33bb1c2866f2dde2a43284dbfb125 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 28 Apr 2014 14:46:18 -0700 Subject: [PATCH 1/5] should be Fatal here --- tail_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tail_test.go b/tail_test.go index ab3bfbe..a955f4d 100644 --- a/tail_test.go +++ b/tail_test.go @@ -393,9 +393,10 @@ func (t TailTest) VerifyTailOutput(tail *Tail, lines []string) { for idx, line := range lines { tailedLine, ok := <-tail.Lines if !ok { + // tail.Lines is closed and empty. err := tail.Err() if err != nil { - t.Errorf("tail ended with error: %v", err) + t.Fatalf("tail ended with error: %v", err) } t.Fatalf("tail ended early; expecting more: %v", lines[idx:]) } From afbbb638b520c4ab9accea5f7ea6be81a898f160 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 28 Apr 2014 14:46:42 -0700 Subject: [PATCH 2/5] add failing test case --- tail_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tail_test.go b/tail_test.go index a955f4d..219aacc 100644 --- a/tail_test.go +++ b/tail_test.go @@ -265,16 +265,22 @@ func TestRateLimiting(_t *testing.T) { LimitRate: 2} expecting := "Too much log activity (more than 2 lines per second being written); waiting a second before resuming tailing" tail := t.StartTail("test.txt", config) + // TODO: also verify that tail resumes after the cooloff period. go t.VerifyTailOutput( tail, - []string{"hello", "world", "again", expecting}) + []string{"hello", "world", "again", expecting, "more", "data"}) + + // Add more data only after reasonable delay. + <-time.After(1200 * time.Millisecond) + t.AppendFile("test.txt", "more\ndata\n") // Delete after a reasonable delay, to give tail sufficient time // to read all lines. <-time.After(100 * time.Millisecond) t.RemoveFile("test.txt") - tail.Stop() + + // tail.Stop() Cleanup() } From 555e6044cadcf691e29d9b0410c7d995ed2b0952 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 28 Apr 2014 14:51:59 -0700 Subject: [PATCH 3/5] fix for the failing test case (parent commit) --- tail.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tail.go b/tail.go index 34ef4cc..8d87d32 100644 --- a/tail.go +++ b/tail.go @@ -236,6 +236,8 @@ func (tail *Tail) tailFileSync() { tail.Killf("Seek error on %s: %s", tail.Filename, err) return } + // Reset the read buffer whenever the file is re-seek'ed + tail.reader.Reset(tail.file) } } case io.EOF: From c13cdd473cceb2bd5191cd9f65449f51137edbe8 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 28 Apr 2014 14:55:51 -0700 Subject: [PATCH 4/5] refactor seek routine --- tail.go | 16 ++++++++++++---- tail_test.go | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tail.go b/tail.go index 8d87d32..482ca88 100644 --- a/tail.go +++ b/tail.go @@ -231,13 +231,11 @@ func (tail *Tail) tailFileSync() { case <-tail.Dying(): return } - _, err := tail.file.Seek(0, 2) // Seek to fine end + err = tail.seekEnd() if err != nil { - tail.Killf("Seek error on %s: %s", tail.Filename, err) + tail.Kill(err) return } - // Reset the read buffer whenever the file is re-seek'ed - tail.reader.Reset(tail.file) } } case io.EOF: @@ -321,6 +319,16 @@ func (tail *Tail) newReader() *bufio.Reader { } } +func (tail *Tail) seekEnd() error { + _, err := tail.file.Seek(0, 2) + if err != nil { + return fmt.Errorf("Seek error on %s: %s", tail.Filename, err) + } + // Reset the read buffer whenever the file is re-seek'ed + tail.reader.Reset(tail.file) + return nil +} + // sendLine sends the line(s) to Lines channel, splitting longer lines // if necessary. Return false if rate limit is reached. func (tail *Tail) sendLine(line []byte) bool { diff --git a/tail_test.go b/tail_test.go index 219aacc..58b340a 100644 --- a/tail_test.go +++ b/tail_test.go @@ -268,7 +268,7 @@ func TestRateLimiting(_t *testing.T) { // TODO: also verify that tail resumes after the cooloff period. go t.VerifyTailOutput( - tail, + tail, []string{"hello", "world", "again", expecting, "more", "data"}) // Add more data only after reasonable delay. From 3d549f46bde6bd1fe16e958d3ee7b0d0006e71ed Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 28 Apr 2014 14:58:39 -0700 Subject: [PATCH 5/5] update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 498fb58..617a67f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ # Apr, 2014 +* LimitRate now discards read buffer (PR #28) * allow reading of longer lines if MaxLineSize is unset (PR #24) * updated deps.json to latest fsnotify (441bbc86b1)