Skip to content

Commit

Permalink
Merge pull request #1 from AndriiChuzhynov/seek_line
Browse files Browse the repository at this point in the history
Seek line
  • Loading branch information
AndriiChuzhynov committed Jun 3, 2018
2 parents f40ba47 + 4517dd4 commit 3a49d75
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 2,391 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ script:
- go test -race -v ./...

go:
- 1.4
- 1.5
- 1.6
- tip
- "1.7"
- "1.8"
- "1.9"
- "1.10"
- "tip"

matrix:
allow_failures:
- go: tip

install:
- go get gopkg.in/fsnotify.v1
- go get gopkg.in/fsnotify/fsnotify.v1
- go get gopkg.in/tomb.v1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/hpcloud/tail.svg)](https://travis-ci.org/hpcloud/tail)
[![Build status](https://ci.appveyor.com/api/projects/status/kohpsf3rvhjhrox6?svg=true)](https://ci.appveyor.com/project/HelionCloudFoundry/tail)
[![Build status](https://ci.appveyor.com/api/projects/status/vrl3paf9md0a7bgk/branch/master?svg=true)](https://ci.appveyor.com/project/Nino-K/tail/branch/master)

# Go package for tail-ing files

Expand Down
2 changes: 1 addition & 1 deletion cmd/gotail/gotail.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"os"

"github.com/hpcloud/tail"
"github.com/AndriiChuzhynov/tail"
)

func args2config() (tail.Config, int64) {
Expand Down
10 changes: 6 additions & 4 deletions ratelimiter/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"time"
)

const GC_SIZE int = 100
const (
GC_SIZE int = 100
GC_PERIOD time.Duration = 60 * time.Second
)

type Memory struct {
store map[string]LeakyBucket
Expand Down Expand Up @@ -44,11 +47,10 @@ func (m *Memory) GarbageCollect() {
now := time.Now()

// rate limit GC to once per minute
if now.Add(60*time.Second).Unix() > m.lastGCCollected.Unix() {

if now.Unix() >= m.lastGCCollected.Add(GC_PERIOD).Unix() {
for key, bucket := range m.store {
// if the bucket is drained, then GC
if bucket.DrainedAt().Unix() > now.Unix() {
if bucket.DrainedAt().Unix() < now.Unix() {
delete(m.store, key)
}
}
Expand Down
6 changes: 3 additions & 3 deletions tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"sync"
"time"

"github.com/hpcloud/tail/ratelimiter"
"github.com/hpcloud/tail/util"
"github.com/hpcloud/tail/watch"
"github.com/AndriiChuzhynov/tail/ratelimiter"
"github.com/AndriiChuzhynov/tail/util"
"github.com/AndriiChuzhynov/tail/watch"
"gopkg.in/tomb.v1"
)

Expand Down
60 changes: 51 additions & 9 deletions tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"testing"
"time"

"github.com/hpcloud/tail/ratelimiter"
"github.com/hpcloud/tail/watch"
"github.com/AndriiChuzhynov/tail/ratelimiter"
"github.com/AndriiChuzhynov/tail/watch"
)

func init() {
Expand Down Expand Up @@ -342,13 +342,21 @@ func reOpen(t *testing.T, poll bool) {
"test.txt",
Config{Follow: true, ReOpen: true, Poll: poll})
content := []string{"hello", "world", "more", "data", "endofworld"}
go tailTest.ReadLines(tail, content)
go tailTest.VerifyTailOutput(tail, content, false)

// deletion must trigger reopen
<-time.After(delay)
tailTest.RemoveFile("test.txt")
<-time.After(delay)
tailTest.CreateFile("test.txt", "more\ndata\n")
if poll {
// deletion must trigger reopen
<-time.After(delay)
tailTest.RemoveFile("test.txt")
<-time.After(delay)
tailTest.CreateFile("test.txt", "more\ndata\n")
} else {
// In inotify mode, fsnotify is currently unable to deliver notifications
// about deletion of open files, so we are not testing file deletion.
// (see https://github.com/fsnotify/fsnotify/issues/194 for details).
<-time.After(delay)
tailTest.AppendToFile("test.txt", "more\ndata\n")
}

// rename must trigger reopen
<-time.After(delay)
Expand All @@ -365,7 +373,34 @@ func reOpen(t *testing.T, poll bool) {
// Do not bother with stopping as it could kill the tomb during
// the reading of data written above. Timings can vary based on
// test environment.
tail.Cleanup()
tailTest.Cleanup(tail, false)
}

func TestInotify_WaitForCreateThenMove(t *testing.T) {
tailTest := NewTailTest("wait-for-create-then-reopen", t)
os.Remove(tailTest.path + "/test.txt") // Make sure the file does NOT exist.

tail := tailTest.StartTail(
"test.txt",
Config{Follow: true, ReOpen: true, Poll: false})

content := []string{"hello", "world", "endofworld"}
go tailTest.VerifyTailOutput(tail, content, false)

time.Sleep(50 * time.Millisecond)
tailTest.CreateFile("test.txt", "hello\nworld\n")
time.Sleep(50 * time.Millisecond)
tailTest.RenameFile("test.txt", "test.txt.rotated")
time.Sleep(50 * time.Millisecond)
tailTest.CreateFile("test.txt", "endofworld\n")
time.Sleep(50 * time.Millisecond)
tailTest.RemoveFile("test.txt.rotated")
tailTest.RemoveFile("test.txt")

// Do not bother with stopping as it could kill the tomb during
// the reading of data written above. Timings can vary based on
// test environment.
tailTest.Cleanup(tail, false)
}

func reSeek(t *testing.T, poll bool) {
Expand Down Expand Up @@ -425,6 +460,13 @@ func (t TailTest) CreateFile(name string, contents string) {
}
}

func (t TailTest) AppendToFile(name string, contents string) {
err := ioutil.WriteFile(t.path+"/"+name, []byte(contents), 0600|os.ModeAppend)
if err != nil {
t.Fatal(err)
}
}

func (t TailTest) RemoveFile(name string) {
err := os.Remove(t.path + "/" + name)
if err != nil {
Expand Down
6 changes: 0 additions & 6 deletions vendor/gopkg.in/fsnotify.v1/.gitignore

This file was deleted.

20 changes: 0 additions & 20 deletions vendor/gopkg.in/fsnotify.v1/.travis.yml

This file was deleted.

34 changes: 0 additions & 34 deletions vendor/gopkg.in/fsnotify.v1/AUTHORS

This file was deleted.

Loading

0 comments on commit 3a49d75

Please sign in to comment.