Skip to content

Commit

Permalink
Add Non single byte end of read buffer test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengtianbao committed Jul 12, 2022
1 parent 2c52c51 commit 4ba57b0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/tailer/logstream/filestream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,47 @@ func TestFileStreamRead(t *testing.T) {
wg.Wait()
}

func TestFileStreamReadNonSingleByteEnd(t *testing.T) {
var wg sync.WaitGroup

tmpDir := testutil.TestTempDir(t)

name := filepath.Join(tmpDir, "log")
f := testutil.TestOpenFile(t, name)
defer f.Close()

lines := make(chan *logline.LogLine, 1)
ctx, cancel := context.WithCancel(context.Background())
waker, awaken := waker.NewTest(ctx, 1)
fs, err := logstream.New(ctx, &wg, waker, name, lines, true)
testutil.FatalIfErr(t, err)
awaken(1)

s := "a"
for i := 0; i < 4094; i++ {
s += "a"
}

s += "中"
testutil.WriteString(t, f, s+"\n")
awaken(1)

fs.Stop()
wg.Wait()
close(lines)
received := testutil.LinesReceived(lines)
expected := []*logline.LogLine{
{context.TODO(), name, s},
}
testutil.ExpectNoDiff(t, expected, received, testutil.IgnoreFields(logline.LogLine{}, "Context"))

if !fs.IsComplete() {
t.Errorf("expecting filestream to be complete because stopped")
}
cancel()
wg.Wait()
}

func TestFileStreamTruncation(t *testing.T) {
var wg sync.WaitGroup

Expand Down

0 comments on commit 4ba57b0

Please sign in to comment.