MCPcopy Index your code
hub / github.com/tailscale/tailscale / TestAutoRetry

Function TestAutoRetry

cmd/testwrapper/testwrapper_test.go:116–166  ·  view source on GitHub ↗

TestAutoRetry covers a non-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 a fake /issues/UNKNOWN URL, and have run the test twice.

(t *testing.T)

Source from the content-addressed store, hash-verified

114// passes on retry: the wrapper must exit 0, emit a flakytest failures JSON
115// line with a fake /issues/UNKNOWN URL, and have run the test twice.
116func TestAutoRetry(t *testing.T) {
117 t.Parallel()
118
119 testfile := filepath.Join(t.TempDir(), "autoretry_test.go")
120 // Note: no flakytest.Mark call. The wrapper should retry anyway.
121 code := []byte(`package autoretry_test
122
123import (
124 "os"
125 "testing"
126)
127
128func TestAutoFlake(t *testing.T) {
129 e := os.Getenv("TS_TESTWRAPPER_ATTEMPT")
130 if e == "" {
131 t.Skip("not running in testwrapper")
132 }
133 if e == "1" {
134 t.Fatal("First run in testwrapper, failing so that test is retried. This is expected.")
135 }
136}
137`)
138 if err := os.WriteFile(testfile, code, 0o644); err != nil {
139 t.Fatalf("writing package: %s", err)
140 }
141
142 out, err := cmdTestwrapper(t, "-v", testfile).CombinedOutput()
143 if err != nil {
144 t.Fatalf("testwrapper %s: %s with output:\n%s", testfile, err, out)
145 }
146
147 if !bytes.Contains(out, []byte("flakytest failures JSON:")) {
148 t.Errorf("missing flakytest failures JSON line in output:\n%s", out)
149 }
150 if !bytes.Contains(out, []byte("/issues/UNKNOWN")) {
151 t.Errorf("missing fake /issues/UNKNOWN URL in output:\n%s", out)
152 }
153 if !bytes.Contains(out, []byte("https://github.com/tailscale/tailscale/issues/UNKNOWN")) {
154 t.Errorf("missing fake URL with detected repo in output:\n%s", out)
155 }
156 if bytes.Contains(out, []byte("permanent test failures JSON:")) {
157 t.Errorf("unexpected permanent failures line in output:\n%s", out)
158 }
159 if runs := bytes.Count(out, []byte("=== RUN TestAutoFlake")); runs != 2 {
160 t.Errorf("expected TestAutoFlake to run twice but ran %d times in output:\n%s", runs, out)
161 }
162
163 if testing.Verbose() {
164 t.Logf("success - output:\n%s", out)
165 }
166}
167
168// TestPermanentFailure covers a test that always fails: the wrapper must exit
169// non-zero, emit a permanent test failures JSON line, and NOT emit a flakytest

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…