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)
| 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. |
| 116 | func 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 | |
| 123 | import ( |
| 124 | "os" |
| 125 | "testing" |
| 126 | ) |
| 127 | |
| 128 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…