diff --git a/cmd/testwrapper/flakytest/flakytest.go b/cmd/testwrapper/flakytest/flakytest.go index 475a843ec..8b9dcd980 100644 --- a/cmd/testwrapper/flakytest/flakytest.go +++ b/cmd/testwrapper/flakytest/flakytest.go @@ -19,7 +19,8 @@ import ( const FlakyTestLogMessage = "flakytest: this is a known flaky test" // FlakeAttemptEnv is an environment variable that is set by cmd/testwrapper -// when a flaky test is retried. It contains the attempt number, starting at 1. +// when a flaky test is being (re)tried. It contains the attempt number, +// starting at 1. const FlakeAttemptEnv = "TS_TESTWRAPPER_ATTEMPT" var issueRegexp = regexp.MustCompile(`\Ahttps://github\.com/tailscale/[a-zA-Z0-9_.-]+/issues/\d+\z`) @@ -33,7 +34,11 @@ func Mark(t testing.TB, issue string) { if !issueRegexp.MatchString(issue) { t.Fatalf("bad issue format: %q", issue) } - - fmt.Fprintln(os.Stderr, FlakyTestLogMessage) // sentinel value for testwrapper + if _, ok := os.LookupEnv(FlakeAttemptEnv); ok { + // We're being run under cmd/testwrapper so send our sentinel message + // to stderr. (We avoid doing this when the env is absent to avoid + // spamming people running tests without the wrapper) + fmt.Fprintln(os.Stderr, FlakyTestLogMessage) + } t.Logf("flakytest: issue tracking this flaky test: %s", issue) }