Skip to content

Commit

Permalink
Chore: Close FDs on TestFileConsole to avoid issues on Win
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez authored and mstoykov committed Mar 7, 2025
1 parent 0bc1359 commit e8e93e5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/js/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ func TestFileConsole(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "") //nolint:forbidigo // fix with https://github.com/grafana/k6/issues/2565
require.NoError(t, err)
logFilename := f.Name()
defer os.Remove(logFilename) //nolint:errcheck,forbidigo // fix with https://github.com/grafana/k6/issues/2565
// close it as we will want to reopen it and maybe remove it
if deleteFile {
require.NoError(t, f.Close())
Expand Down Expand Up @@ -410,6 +409,11 @@ func TestFileConsole(t *testing.T) {

vu := initVU.Activate(&lib.VUActivationParams{RunContext: ctx})
logger := extractLogger(vu)
t.Cleanup(func() {
if loggerOut, canBeClosed := logger.Out.(io.Closer); canBeClosed {
require.NoError(t, loggerOut.Close())
}
})

logger.Level = logrus.DebugLevel
hook := logtest.NewLocal(logger)
Expand Down Expand Up @@ -442,6 +446,7 @@ func TestFileConsole(t *testing.T) {

fileContent, err := io.ReadAll(f)
require.NoError(t, err)
require.NoError(t, f.Close())

expectedStr := entryStr
if !deleteFile {
Expand Down

0 comments on commit e8e93e5

Please sign in to comment.