MCPcopy
hub / github.com/tailscale/tailscale / TestRetry

Function TestRetry

cmd/testwrapper/testwrapper_test.go:58–111  ·  view source on GitHub ↗

TestRetry covers a Mark()'d test that fails on the first attempt and passes on retry: the wrapper must exit 0, emit a flakytest failures JSON line with the real issue URL, and have run TestFlakeRun twice.

(t *testing.T)

Source from the content-addressed store, hash-verified

56// on retry: the wrapper must exit 0, emit a flakytest failures JSON line with
57// the real issue URL, and have run TestFlakeRun twice.
58func TestRetry(t *testing.T) {
59 t.Parallel()
60
61 testfile := filepath.Join(t.TempDir(), "retry_test.go")
62 code := []byte(`package retry_test
63
64import (
65 "os"
66 "testing"
67 "tailscale.com/cmd/testwrapper/flakytest"
68)
69
70func TestOK(t *testing.T) {}
71
72func TestFlakeRun(t *testing.T) {
73 flakytest.Mark(t, "https://github.com/tailscale/tailscale/issues/1234")
74 e := os.Getenv(flakytest.FlakeAttemptEnv)
75 if e == "" {
76 t.Skip("not running in testwrapper")
77 }
78 if e == "1" {
79 t.Fatal("First run in testwrapper, failing so that test is retried. This is expected.")
80 }
81}
82`)
83 if err := os.WriteFile(testfile, code, 0o644); err != nil {
84 t.Fatalf("writing package: %s", err)
85 }
86
87 out, err := cmdTestwrapper(t, "-v", testfile).CombinedOutput()
88 if err != nil {
89 t.Fatalf("go run . %s: %s with output:\n%s", testfile, err, out)
90 }
91
92 if !bytes.Contains(out, []byte("flakytest failures JSON:")) {
93 t.Errorf("missing flakytest failures JSON line in output:\n%s", out)
94 }
95 if !bytes.Contains(out, []byte("https://github.com/tailscale/tailscale/issues/1234")) {
96 t.Errorf("missing real issue URL in output:\n%s", out)
97 }
98 if bytes.Contains(out, []byte("permanent test failures JSON:")) {
99 t.Errorf("unexpected permanent failures line in output:\n%s", out)
100 }
101 if okRuns := bytes.Count(out, []byte("=== RUN TestOK")); okRuns != 1 {
102 t.Errorf("expected TestOK to be run once but was run %d times in output:\n%s", okRuns, out)
103 }
104 if flakeRuns := bytes.Count(out, []byte("=== RUN TestFlakeRun")); flakeRuns != 2 {
105 t.Errorf("expected TestFlakeRun to be run twice but was run %d times in output:\n%s", flakeRuns, out)
106 }
107
108 if testing.Verbose() {
109 t.Logf("success - output:\n%s", out)
110 }
111}
112
113// TestAutoRetry covers a non-Mark()'d test that fails on the first attempt and
114// passes on retry: the wrapper must exit 0, emit a flakytest failures JSON

Callers

nothing calls this directly

Calls 8

cmdTestwrapperFunction · 0.85
CombinedOutputMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
FatalfMethod · 0.65
ErrorfMethod · 0.65
LogfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…