Skip to content

Commit

Permalink
Fix flushing log stream in tests (#13289)
Browse files Browse the repository at this point in the history
* Fix flushing log stream in tests

* Refactor
  • Loading branch information
lukaszcl authored May 22, 2024
1 parent e728464 commit 29b51c8
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,24 +287,8 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
b.l.Info().Str("Absolute path", logPath).Msg("LogStream logs folder location")
}

var flushLogStreamFn = func() error {
// we can't do much if this fails, so we just log the error in LogStream
if flushErr := b.te.LogStream.FlushAndShutdown(); flushErr != nil {
b.l.Error().Err(flushErr).Msg("Error flushing and shutting down LogStream")
return flushErr
}
b.te.LogStream.PrintLogTargetsLocations()
b.te.LogStream.SaveLogLocationInTestSummary()

return nil
}

// flush logs when test failed or when we are explicitly told to collect logs
if b.t.Failed() || *b.testConfig.GetLoggingConfig().TestLogCollect {
if shutdownErr := flushLogStreamFn(); shutdownErr != nil {
return
}
}
flushLogStream := b.t.Failed() || *b.testConfig.GetLoggingConfig().TestLogCollect

// run even if test has failed, as we might be able to catch additional problems without running the test again
if b.chainlinkNodeLogScannerSettings != nil {
Expand All @@ -329,13 +313,21 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
b.l.Error().Err(err).Msg("Error processing logs")
return
} else if err != nil && (strings.Contains(err.Error(), testreporters.MultipleLogsAtLogLevelErr) || strings.Contains(err.Error(), testreporters.OneLogAtLogLevelErr)) {
// err return ignored on purpose since we are already failing the test
_ = flushLogStreamFn()
flushLogStream = true
b.t.Fatalf("Found a concerning log in Chainklink Node logs: %v", err)
}
}
b.l.Info().Msg("Finished scanning Chainlink Node logs for concerning errors")
}

if flushLogStream {
// we can't do much if this fails, so we just log the error in LogStream
if err := b.te.LogStream.FlushAndShutdown(); err != nil {
b.l.Error().Err(err).Msg("Error flushing and shutting down LogStream")
}
b.te.LogStream.PrintLogTargetsLocations()
b.te.LogStream.SaveLogLocationInTestSummary()
}
})
} else {
b.l.Warn().Msg("LogStream won't be cleaned up, because test instance is not set or cleanup type is not standard")
Expand Down

0 comments on commit 29b51c8

Please sign in to comment.