Skip to content

report test2json: report repeated runs of a test as retries - #45

Open
DzmitryHumianiuk wants to merge 2 commits into
feat/test2json-build-failuresfrom
feat/test2json-retries
Open

DzmitryHumianiuk wants to merge 2 commits into
feat/test2json-build-failuresfrom
feat/test2json-retries

Conversation

@DzmitryHumianiuk

Copy link
Copy Markdown
Member

Summary

Part of #26 (slice C5). Stacked on C4 → C3 → C2 → #29.

One go test -json stream can contain several runs of the same test: go test -count=N, and
gotestsum --rerun-fails --jsonfile. Until now each run was a separate item with retry=false, so the launch
counted every run. This PR reports the later runs as ReportPortal retries.

This changes launch statistics for -count=N users. Please read "Behaviour change" and put it in the release
notes.

Changes

  • A repeated run of a test without subtests is started with retry=true and retryOf = the UUID of the run
    before it (always the latest run, see Investigation log 3).
  • A test with subtests and the suite of a package are not started again. Their item is reused
    (reopen) and finished again when the run ends. Their subtests then find their previous run under the same
    parent and become retries; subtests that do not run again stay as they are.
  • A container that is finished again gets FAILED instead of PASSED while a test below it still has a failed
    last run (containerStatus). This happens in a gotestsum stream: the rerun of one test passes while another test
    of the package has not been rerun yet.
  • Launch status (with retries on): FAILED when the last run of a test or the last result of a package
    failed (launchFailed). Before, any fail event failed the launch.
  • --retries (REPORT_RETRIES, default true). With --retries=false nothing of the above applies: every run is
    a separate item and any failure fails the launch, exactly as before.
  • Fixtures internal/commands/testdata/retries/: unedited output of go1.27.4 (-count=2, -count=3) and
    gotestsum v1.12.3 (--rerun-fails).
  • e2e: three tests that assert retries and launch statistics on a real server. The e2e item view got retries.
  • README (new section "Repeated runs (retries)"), skill, AGENTS.md.

Behaviour change

For an input in which tests run more than once, with the default --retries=true:

before now
go test -count=3, 10 tests total 30 total 10, each item has 2 retries
test fails in run 1, passes in run 2 1 failed + 1 passed item 1 passed item with a FAILED retry
launch status, -count=N with a failed run FAILED FAILED (go test fails the package)
launch status, gotestsum rerun passes FAILED PASSED
suite of a package that gotestsum reruns finished once, later runs added under the finished suite reused and finished again with the latest status

A failure in an earlier run is therefore no longer visible in the executions numbers, only as a retry of the item
(and, for -count=N, in the FAILED status of suite and launch). Users who run -count=N to count failures
should set --retries=false.

Inputs without repeated runs are reported exactly as before.

Verification

  • go build ./... && go vet ./... && go test -race ./...: ok. Lint (run ./..., run --build-tags e2e ./e2e/...):
    0 issues.
  • Unit (internal/commands/report_retries_test.go, real streams, with and without --reportEmptyPkg):
    retry chains (retry, retryOf = previous run, same parent, same testCaseId), third run is a retry of the
    second, containers started once and finished FAILED then PASSED, the gotestsum suite finished
    FAILED, FAILED, PASSED, launch status, --retries=false, and nested import paths.
  • Live, ReportPortal 6.0.0 (demo): go test -tags e2e -count=1 -v -run Retries ./e2e/...
    • PASS TestReportTest2JSON_CountRunsAreRetries (4.94s): -count=2 stream → executions total 6, passed 6,
      failed 0; hasRetries; launch FAILED; 9 items; TestFlaky PASSED with retries [FAILED];
      TestTable one item, PASSED, no retries, parent of ok and flaky, which have one retry each.
    • PASS TestReportTest2JSON_GotestsumRerunsAreRetries (3.83s): total 6, passed 6; launch PASSED;
      TestFlaky and TestTable/flaky have a FAILED retry; tests that did not run again have none; suite PASSED.
    • PASS TestReportTest2JSON_RetriesDisabled (4.49s): -count=2 with --retries=false → total 12, passed 10,
      failed 2, no retries, launch FAILED.

Investigation log

  1. Real streams first (scratchpad/wave/mkretries.sh, output in scratchpad/wave/retries/out/):
    • -count=2: one start and one result per package; inside it all tests run, then all tests run again.
    • gotestsum: after the normal run it appends, per failed top-level test, a complete run of the package
      (start … pass/fail of the package). The rerun of TestTable contains TestTable and only the failed
      subtest TestTable/flaky, not TestTable/ok.
  2. How the server groups retries, source: service-api develop,
    src/main/java/com/epam/reportportal/base/core/item/impl/StartTestItemHandlerImpl.java:136-141
    (isRetry = retry || retryOf), core/item/impl/retry/RetryHandlerImpl.java:51-99: with retryOf, the named
    item is demoted and the new item becomes the main one (handleExplicitRetry); an unknown retryOf falls back
    to grouping by uniqueId + parent; if (target.getRetryOf() != null …) { log.warn("… already a retry …, skipping"); return; }.
  3. The same, observed (scratchpad/wave/probe_c5.py, raw v2 requests, log scratchpad/wave/live/c5-probe.log):
    • leaf_chain (run 3 retryOf run 2): one item PASSED, retries=[FAILED, FAILED], executions total counts
      it once.
    • stale_retry_of (run 3 retryOf run 1): run 3 became a second counted item (total 2: passed 1, failed 1).
      So retryOf must be the latest run; the reporter keeps the latest UUID per test in r.tests.
    • no_retry_flag (what gorp did): three counted items.
  4. Tests with subtests. Three designs were probed:
    • parent_with_children: the parent's second run is a retry of the first. Statistics are right for a complete
      rerun, but the children of the first run disappear under the retry. With a gotestsum stream the passed
      subtest that is not rerun (TestTable/ok) would vanish from the statistics.
    • children_retry_across_parents: parents as two plain items, subtests linked with retryOf. Statistics are
      right, but an empty FAILED parent is left behind.
    • reuse_container (chosen): keep the one parent item, start the rerun subtest under it with retryOf, finish
      the parent and the suite again. Result: suite and parent PASSED, ok untouched, flaky PASSED with
      retries=[FAILED], total 2, passed 2.
    • leaf_then_container: a test that was a leaf in run 1 and has subtests in run 2 also works (the parent is a
      retry once, its subtest is retried under the reused parent later).
  5. Is finishing an item twice allowed? core/item/impl/FinishTestItemHandlerImpl.java:211-216,270-300: an item
    with children (or a type above STEP) goes through processParentItemResult, which has no "already finished"
    check, sets the status from the request and updates the parent and launch status. Observed in the
    finished_suite_reused and reuse_container probes: the second finish was applied.
  6. The suite of a rerun package: finished_suite_reused (chosen) gives one PASSED suite; new_suite_per_run
    leaves a FAILED suite next to a PASSED one with the same name.
  7. Launch status. With "any failure fails the launch" the gotestsum stream gave a FAILED launch whose items are
    all PASSED, while gotestsum itself exits 0. A package-level result alone is not enough either: gotestsum
    reruns tests one by one, so the last result of a package can be a pass while another test's last run failed.
    Hence both the last result per test and per package are tracked.
  8. A previous run that is still open is not treated as a previous run. Go makes duplicate subtest names unique
    with #01, so a second run of an open test needs a test that never got its result. Checked with a real
    stream (scratchpad/wave/mkcrash.sh: one package panics, one runs into -timeout, under
    gotestsum --rerun-fails): a panic still produces fail events for the running tests; a timeout leaves
    TestHangs without a result, but gotestsum then stops with rerun aborted because previous run had a suspected panic, so no second run follows. With go test -count=N the timeout ends the package as well. The case is
    therefore left as "report it as a new item".
  9. Failure state is kept per package and test name separately (testKey), not by the joined name: an import path
    can be the prefix of another (m/a, m/a/b), and a first version that matched on the joined name failed the
    suite of m/a for a failed test of m/a/b. TestReportLaunch_NestedPackageDoesNotFailItsParentPackage
    covers this and the same trap for test names (TestZ / TestZoo).
  10. The test helpers reportCmd and test2jsonCmd now define retries with the CLI's default (true), so all
    earlier reporter tests run in the configuration that ships.

Open questions

  • Is --retries wanted, or should retries be unconditional? It was added because the default hides earlier
    failures from the executions numbers, which is the point of -count=N for some users.
  • For -count=N the launch can be FAILED with zero failed items. That follows go test's exit code. An
    alternative is to pass the launch when every last run passed.

Not verified

  • Servers older than 6.0.0. handleExplicitRetry exists since 5.15.2 according to
    scratchpad/consilium2/server.md; before that the fallback for retryOf and finishing an item twice were not
    checked.
  • How the UI presents retries of a subtest under a reused parent (API only).
  • -count=N together with -parallel or -shuffle; benchmarks.
  • gotestsum --rerun-fails with more than one rerun round, and with --rerun-fails-run-root-test. Only the unit
    tests' real stream (one round) was used.

🤖 Generated with Claude Code

A test can run more than once in one stream: 'go test -count=N' and
'gotestsum --rerun-fails'. Every run was a separate, counted item.

A further run of a test without subtests is now started with retry=true
and retryOf = the UUID of the run before it. It has to be the latest run:
the server skips a retryOf that points to an item which is a retry
itself. A test with subtests and the suite of a package are containers
that are not counted: their item is reused and finished again, so the
subtests that run again become retries under the same parent and those
that do not (gotestsum reruns only the failed ones) stay counted.

The launch is FAILED when the last run of a test or a package failed, so
a run that gotestsum made pass is a passed launch.

This changes the statistics of -count=N: N runs of a test are one
execution with N-1 retries. --retries=false keeps the previous behaviour.

Part of #26.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants