Repository navigation
report test2json: report repeated runs of a test as retries - #45
Open
DzmitryHumianiuk wants to merge 2 commits into
Open
DzmitryHumianiuk wants to merge 2 commits into
DzmitryHumianiuk wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #26 (slice C5). Stacked on C4 → C3 → C2 → #29.
One
go test -jsonstream can contain several runs of the same test:go test -count=N, andgotestsum --rerun-fails --jsonfile. Until now each run was a separate item withretry=false, so the launchcounted every run. This PR reports the later runs as ReportPortal retries.
This changes launch statistics for
-count=Nusers. Please read "Behaviour change" and put it in the releasenotes.
Changes
retry=trueandretryOf= the UUID of the runbefore it (always the latest run, see Investigation log 3).
(
reopen) and finished again when the run ends. Their subtests then find their previous run under the sameparent and become retries; subtests that do not run again stay as they are.
FAILEDinstead ofPASSEDwhile a test below it still has a failedlast run (
containerStatus). This happens in a gotestsum stream: the rerun of one test passes while another testof the package has not been rerun yet.
FAILEDwhen the last run of a test or the last result of a packagefailed (
launchFailed). Before, anyfailevent failed the launch.--retries(REPORT_RETRIES, defaulttrue). With--retries=falsenothing of the above applies: every run isa separate item and any failure fails the launch, exactly as before.
internal/commands/testdata/retries/: unedited output of go1.27.4 (-count=2,-count=3) andgotestsum v1.12.3 (
--rerun-fails).retries.Behaviour change
For an input in which tests run more than once, with the default
--retries=true:go test -count=3, 10 teststotal 30total 10, each item has 2 retriesFAILEDretry-count=Nwith a failed runFAILEDFAILED(go test fails the package)FAILEDPASSEDA 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 theFAILEDstatus of suite and launch). Users who run-count=Nto count failuresshould 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.
internal/commands/report_retries_test.go, real streams, with and without--reportEmptyPkg):retry chains (
retry,retryOf= previous run, same parent, sametestCaseId), third run is a retry of thesecond, containers started once and finished
FAILEDthenPASSED, the gotestsum suite finishedFAILED, FAILED, PASSED, launch status,--retries=false, and nested import paths.go test -tags e2e -count=1 -v -run Retries ./e2e/...PASS TestReportTest2JSON_CountRunsAreRetries (4.94s):-count=2stream → executions total 6, passed 6,failed 0;
hasRetries; launchFAILED; 9 items;TestFlakyPASSEDwith retries[FAILED];TestTableone item,PASSED, no retries, parent ofokandflaky, which have one retry each.PASS TestReportTest2JSON_GotestsumRerunsAreRetries (3.83s): total 6, passed 6; launchPASSED;TestFlakyandTestTable/flakyhave aFAILEDretry; tests that did not run again have none; suitePASSED.PASS TestReportTest2JSON_RetriesDisabled (4.49s):-count=2with--retries=false→ total 12, passed 10,failed 2, no retries, launch
FAILED.Investigation log
scratchpad/wave/mkretries.sh, output inscratchpad/wave/retries/out/):-count=2: onestartand one result per package; inside it all tests run, then all tests run again.(
start…pass/failof the package). The rerun ofTestTablecontainsTestTableand only the failedsubtest
TestTable/flaky, notTestTable/ok.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: withretryOf, the nameditem is demoted and the new item becomes the main one (
handleExplicitRetry); an unknownretryOffalls backto grouping by
uniqueId+ parent;if (target.getRetryOf() != null …) { log.warn("… already a retry …, skipping"); return; }.scratchpad/wave/probe_c5.py, raw v2 requests, logscratchpad/wave/live/c5-probe.log):leaf_chain(run 3retryOfrun 2): one itemPASSED,retries=[FAILED, FAILED], executions total countsit once.
stale_retry_of(run 3retryOfrun 1): run 3 became a second counted item (total 2: passed 1, failed 1).So
retryOfmust be the latest run; the reporter keeps the latest UUID per test inr.tests.no_retry_flag(what gorp did): three counted items.parent_with_children: the parent's second run is a retry of the first. Statistics are right for a completererun, 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 withretryOf. Statistics areright, but an empty
FAILEDparent is left behind.reuse_container(chosen): keep the one parent item, start the rerun subtest under it withretryOf, finishthe parent and the suite again. Result: suite and parent
PASSED,okuntouched,flakyPASSEDwithretries=[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 aretry once, its subtest is retried under the reused parent later).
core/item/impl/FinishTestItemHandlerImpl.java:211-216,270-300: an itemwith children (or a type above
STEP) goes throughprocessParentItemResult, which has no "already finished"check, sets the status from the request and updates the parent and launch status. Observed in the
finished_suite_reusedandreuse_containerprobes: the second finish was applied.finished_suite_reused(chosen) gives onePASSEDsuite;new_suite_per_runleaves a
FAILEDsuite next to aPASSEDone with the same name.FAILEDlaunch whose items areall
PASSED, while gotestsum itself exits 0. A package-level result alone is not enough either: gotestsumreruns 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.
with
#01, so a secondrunof an open test needs a test that never got its result. Checked with a realstream (
scratchpad/wave/mkcrash.sh: one package panics, one runs into-timeout, undergotestsum --rerun-fails): a panic still producesfailevents for the running tests; a timeout leavesTestHangswithout a result, but gotestsum then stops withrerun aborted because previous run had a suspected panic, so no second run follows. Withgo test -count=Nthe timeout ends the package as well. The case istherefore left as "report it as a new item".
testKey), not by the joined name: an import pathcan be the prefix of another (
m/a,m/a/b), and a first version that matched on the joined name failed thesuite of
m/afor a failed test ofm/a/b.TestReportLaunch_NestedPackageDoesNotFailItsParentPackagecovers this and the same trap for test names (
TestZ/TestZoo).reportCmdandtest2jsonCmdnow defineretrieswith the CLI's default (true), so allearlier reporter tests run in the configuration that ships.
Open questions
--retrieswanted, or should retries be unconditional? It was added because the default hides earlierfailures from the executions numbers, which is the point of
-count=Nfor some users.-count=Nthe launch can beFAILEDwith zero failed items. That follows go test's exit code. Analternative is to pass the launch when every last run passed.
Not verified
handleExplicitRetryexists since 5.15.2 according toscratchpad/consilium2/server.md; before that the fallback forretryOfand finishing an item twice were notchecked.
-count=Ntogether with-parallelor-shuffle; benchmarks.gotestsum --rerun-failswith more than one rerun round, and with--rerun-fails-run-root-test. Only the unittests' real stream (one round) was used.
🤖 Generated with Claude Code