Skip to content

Commit 9f0d902

Browse files
authored
Improving windows build flakiness (#1931)
1 parent 726d25d commit 9f0d902

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

plugins/inputs/logfile/logfile_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,28 +193,36 @@ func TestCompressedFile(t *testing.T) {
193193

194194
func TestMultipleFilesForSameConfig(t *testing.T) {
195195
multilineWaitPeriod = 10 * time.Millisecond
196-
tmpfile1, err := createTempFile("", "tmp1_")
196+
197+
// Use a unique prefix to avoid matching other temp files
198+
uniquePrefix := fmt.Sprintf("TestMultipleFiles_%d_", time.Now().UnixNano())
199+
200+
tmpfile1, err := createTempFile("", uniquePrefix+"tmp1_")
197201
defer os.Remove(tmpfile1.Name())
198202
require.NoError(t, err)
199203

200204
_, err = tmpfile1.WriteString("1\n")
201205
require.NoError(t, err)
206+
tmpfile1.Sync() // Ensure file is flushed to disk
207+
tmpfile1.Close()
202208

203209
//make file stat reflect the diff of file ModTime
204210
time.Sleep(time.Second * 2)
205211

206-
tmpfile2, err := createTempFile("", "tmp2_")
212+
tmpfile2, err := createTempFile("", uniquePrefix+"tmp2_")
207213
defer os.Remove(tmpfile2.Name())
208214
require.NoError(t, err)
209215

210216
_, err = tmpfile2.WriteString("2\n")
211217
require.NoError(t, err)
218+
tmpfile2.Sync() // Ensure file is flushed to disk
219+
tmpfile2.Close()
212220

213221
logGroupName := "SomeLogGroupName"
214222
tt := NewLogFile()
215223
tt.Log = TestLogger{t}
216224
tt.FileConfig = []FileConfig{{
217-
FilePath: filepath.Dir(tmpfile1.Name()) + string(filepath.Separator) + "*",
225+
FilePath: filepath.Dir(tmpfile1.Name()) + string(filepath.Separator) + uniquePrefix + "*",
218226
FromBeginning: true,
219227
LogGroupName: logGroupName,
220228
}}

plugins/inputs/logfile/tail/tail.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,12 @@ func (tail *Tail) tailFileSync() {
398398
}
399399
}
400400

401-
if err := tail.watchChanges(); err != nil {
402-
tail.Killf("Error watching for changes on %s: %s", tail.Filename, err)
403-
return
401+
// Only set up file watchers if we're following the file
402+
if tail.Follow {
403+
if err := tail.watchChanges(); err != nil {
404+
tail.Killf("Error watching for changes on %s: %s", tail.Filename, err)
405+
return
406+
}
404407
}
405408

406409
var backupOffset int64

0 commit comments

Comments
 (0)