Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Make TestReadRotatingFiles more robust on Windows #36032

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions receiver/filelogreceiver/filelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package filelogreceiver

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -190,9 +191,13 @@ func (rt *rotationTest) Run(t *testing.T) {
if rt.copyTruncate {
// Recreate the backup file
// if backupFileName exists
if _, err = os.Stat(backupFileName); err == nil {
require.NoError(t, os.Remove(backupFileName))
}
require.Eventually(t, func() bool {
// On Windows you can't remove a file if it still has some handle opened to it. So remove the file
// in a loop until any async operation on it is done.
removeErr := os.Remove(backupFileName)
return errors.Is(removeErr, os.ErrNotExist)
}, 5*time.Second, 100*time.Millisecond)

backupFile, openErr := os.OpenFile(backupFileName, os.O_CREATE|os.O_RDWR, 0600)
require.NoError(t, openErr)

Expand Down