From 29b51c86dfe22fa4c7e45b3942a8c2b36218886c Mon Sep 17 00:00:00 2001 From: Lukasz <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 22 May 2024 16:03:32 +0200 Subject: [PATCH] Fix flushing log stream in tests (#13289) * Fix flushing log stream in tests * Refactor --- .../docker/test_env/test_env_builder.go | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index ff6e132368b..852918cc7d4 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -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 { @@ -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")