Skip to content

Commit

Permalink
test: Fix a race condition waiting for the pattern waker attached to …
Browse files Browse the repository at this point in the history
…the directory.
  • Loading branch information
jaqx0r committed May 26, 2024
1 parent 5e470ac commit e99f7e5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions internal/tailer/tail_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,31 @@ func TestTailerOpenRetries(t *testing.T) {
if err := ta.TailPath(logfile); err == nil || !os.IsPermission(err) {
t.Fatalf("Expected a permission denied error here: %s", err)
}
testutil.FatalIfErr(t, ta.RemoveCompletedLogstreams())
ta.awakenPattern(1, 1)

// There testTail includes a pattern poller for tmpDir. Make sure we wait for both.
ta.awakenPattern(1, 2)

glog.Info("remove")
if err := os.Remove(logfile); err != nil {
t.Fatal(err)
}
testutil.FatalIfErr(t, ta.RemoveCompletedLogstreams())
ta.awakenPattern(1, 1)
ta.awakenPattern(2, 2)

glog.Info("openfile")
f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0)
testutil.FatalIfErr(t, err)
//nolint:staticcheck // test code
defer f.Close()
testutil.FatalIfErr(t, err)
testutil.FatalIfErr(t, ta.RemoveCompletedLogstreams())
ta.awakenPattern(1, 1)

ta.awakenPattern(2, 2)
glog.Info("chmod")
if err := os.Chmod(logfile, 0o666); err != nil {
t.Fatal(err)
}
testutil.FatalIfErr(t, ta.RemoveCompletedLogstreams())
ta.awakenPattern(1, 1)

ta.awakenPattern(2, 2) // discover the logfile
ta.awakenStreams(1, 1) // force sync to EOF

glog.Info("write string")
testutil.WriteString(t, f, "\n")
ta.awakenStreams(1, 1)
Expand Down

0 comments on commit e99f7e5

Please sign in to comment.