Skip to content

Commit e05dbbb

Browse files
committed
util: add envAlwaysKeepTestLogsEnabled
This commit adds support for a new environment variable, COCKROACH_ALWAYS_KEEP_TEST_LOGS, which ensures that crdb and test logs are kept even when tests fail. Example usage: ``` ./dev test .... -- --test_env=COCKROACH_ALWAYS_KEEP_TEST_LOGS=true ``` Epic: none Release note: none
1 parent 71bcba2 commit e05dbbb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/util/log/test_log_scope.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/cockroachdb/cockroach/pkg/cli/exit"
1616
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
17+
"github.com/cockroachdb/cockroach/pkg/util/envutil"
1718
"github.com/cockroachdb/cockroach/pkg/util/fileutil"
1819
"github.com/cockroachdb/cockroach/pkg/util/log/channel"
1920
"github.com/cockroachdb/cockroach/pkg/util/log/logconfig"
@@ -23,6 +24,11 @@ import (
2324
"github.com/cockroachdb/errors/oserror"
2425
)
2526

27+
// envAlwaysKeepTestLogsEnabled controls whether test and CRDB logs are kept
28+
// even when the test passes. By default, it’s disabled, so logs are deleted on
29+
// test success.
30+
var envAlwaysKeepTestLogsEnabled = envutil.EnvOrDefaultBool("COCKROACH_ALWAYS_KEEP_TEST_LOGS", false)
31+
2632
// TestLogScope represents the lifetime of a logging output. It
2733
// ensures that the log files are stored in a directory specific to a
2834
// test, and enforces that logging output is not written to this
@@ -410,7 +416,7 @@ func (l *TestLogScope) Close(t tShim) {
410416
t.Fatal(err)
411417
}
412418
inPanic := calledDuringPanic()
413-
if (t.Failed() && !emptyDir) || inPanic {
419+
if (t.Failed() && !emptyDir) || inPanic || envAlwaysKeepTestLogsEnabled {
414420
// If the test failed or there was a panic, we keep the log
415421
// files for further investigation.
416422
if inPanic {

0 commit comments

Comments
 (0)