v0.18.2 resume rotated files instead of replay, keep quiet SSE alive, refuse HEAD on strem path
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -44,3 +45,40 @@ func TestRemoveWatcherPreservesReplacement(t *testing.T) {
|
||||
t.Fatal("finished watcher was not removed")
|
||||
}
|
||||
}
|
||||
|
||||
// A rotated file reappears under its archive name with the same inode. Its
|
||||
// replacement watcher resumes where the original stopped, so a `from = "start"`
|
||||
// source does not re-emit every record the file already delivered.
|
||||
func TestRotatedFileResumesInsteadOfReplaying(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
active := filepath.Join(dir, "session.jsonl")
|
||||
if err := os.WriteFile(active, []byte("one\ntwo\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := os.Stat(active)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inode := info.Sys().(*syscall.Stat_t).Ino
|
||||
|
||||
archive := filepath.Join(dir, "session_260916_120000.jsonl")
|
||||
if err := os.Rename(active, archive); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for name, watcher := range map[string]*fileWatcher{
|
||||
"still tailing the renamed inode": {inode: inode, position: 8},
|
||||
"already moved on from it": {inode: 99, prevInode: inode, prevPosition: 8},
|
||||
} {
|
||||
source := &FileSource{watchers: map[string]*fileWatcher{active: watcher}}
|
||||
position, ok := source.readPosition(archive)
|
||||
if !ok || position != 8 {
|
||||
t.Errorf("%s: position = %d, ok = %v, want 8, true", name, position, ok)
|
||||
}
|
||||
}
|
||||
|
||||
unrelated := &FileSource{watchers: map[string]*fileWatcher{active: {inode: 99}}}
|
||||
if _, ok := unrelated.readPosition(archive); ok {
|
||||
t.Error("a file no watcher has read was treated as rotated")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user