diff options
| author | Paul Scott <paul@tailscale.com> | 2025-02-18 08:29:20 -0800 |
|---|---|---|
| committer | Paul Scott <paul@tailscale.com> | 2025-02-18 08:29:55 -0800 |
| commit | 99865276a7475d2281d1dd6f2310b1e2470a75ac (patch) | |
| tree | fe09dba80854552a7bdb8733a8efc4076c7cfdc9 /cmd/testwrapper/flakytest | |
| parent | 052eefbcceeb8a7df865c348aa9139a0a8cf64b1 (diff) | |
| download | tailscale-icio/testwrapper2.tar.xz tailscale-icio/testwrapper2.zip | |
cmd/testwrapper: wip ideaicio/testwrapper2
Signed-off-by: Paul Scott <paul@tailscale.com>
Diffstat (limited to 'cmd/testwrapper/flakytest')
| -rw-r--r-- | cmd/testwrapper/flakytest/flakytest.go | 11 | ||||
| -rw-r--r-- | cmd/testwrapper/flakytest/flakytest_test.go | 29 |
2 files changed, 38 insertions, 2 deletions
diff --git a/cmd/testwrapper/flakytest/flakytest.go b/cmd/testwrapper/flakytest/flakytest.go index 494ed080b..b983da685 100644 --- a/cmd/testwrapper/flakytest/flakytest.go +++ b/cmd/testwrapper/flakytest/flakytest.go @@ -7,9 +7,9 @@ package flakytest import ( - "fmt" "os" "regexp" + "strings" "testing" ) @@ -38,7 +38,14 @@ func Mark(t testing.TB, issue string) { // 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.Fprintf(os.Stderr, "%s: %s\n", FlakyTestLogMessage, issue) + t.Cleanup(func() { + if t.Failed() { + // FIXME: this won't catch panics because t.Failed() won't yet + // be correctly set. https://github.com/golang/go/issues/49929 + root, _, _ := strings.Cut(t.Name(), "/") + t.Logf("flakytest: retry: %s %s", root, strings.Join(os.Args, " ")) + } + }) } t.Logf("flakytest: issue tracking this flaky test: %s", issue) } diff --git a/cmd/testwrapper/flakytest/flakytest_test.go b/cmd/testwrapper/flakytest/flakytest_test.go index 85e77a939..839f3c46c 100644 --- a/cmd/testwrapper/flakytest/flakytest_test.go +++ b/cmd/testwrapper/flakytest/flakytest_test.go @@ -41,3 +41,32 @@ func TestFlakeRun(t *testing.T) { t.Fatal("First run in testwrapper, failing so that test is retried. This is expected.") } } + +// TestFlakePanic is a test that panics when run in the testwrapper +// for the first time, but succeeds on the second run. +// It's used to test whether the testwrapper retries flaky tests. +func TestFlakeExit(t *testing.T) { + Mark(t, "https://github.com/tailscale/tailscale/issues/0") // random issue + e := os.Getenv(FlakeAttemptEnv) + if e == "" { + t.Skip("not running in testwrapper") + } + if e == "1" { + t.Log("First run in testwrapper, failing so exiting so test is retried. This is expected.") + os.Exit(0) + } +} + +// TestFlakePanic is a test that panics when run in the testwrapper +// for the first time, but succeeds on the second run. +// It's used to test whether the testwrapper retries flaky tests. +func TestFlakePanic(t *testing.T) { + Mark(t, "https://github.com/tailscale/tailscale/issues/0") // random issue + e := os.Getenv(FlakeAttemptEnv) + if e == "" { + t.Skip("not running in testwrapper") + } + if e == "1" { + panic("First run in testwrapper, failing so that test is retried. This is expected.") + } +} |
