Skip to content

--publish-azdo-test-results creates one Azure DevOps test run per --retry-failed-tests attempt instead of one run per build #10360

Closed

Description

Describe the bug

When --publish-azdo-test-results is used together with the Retry extension (--retry-failed-tests N), each retry attempt creates and completes its own Azure DevOps test run. A test that fails on the first attempt and passes on a retry ends up recorded as Failed in one run and Passed in another, with nothing tying them together.

The platform itself has the information — it prints flaky: 1 (passed after retry) and a Flaky tests: ... (failed -> passed) section — but that is lost when publishing.

PublishTestResults@2 with AllowPtrToDetectTestRunRetryFiles: true handles the same situation correctly: it publishes every attempt into a single run and updates each result, so the run ends with one entry per test carrying its final outcome.

This is not the crash from #10191. That one masks this behaviour on the released 2.3.3, because the publisher dies in Dispose() before any retry can run. Everything below is on preview builds that contain the #10291 fix, where the crash is gone and the retry does run.

Version used

Reproduced on:

  • Microsoft.Testing.Extensions.AzureDevOpsReport 2.4.0-preview.26381.1 (latest on the test-tools nightly feed at the time of writing) and 2.4.0-preview.26378.13
  • Microsoft.Testing.Extensions.Retry 2.4.0-preview.26381.1
  • MSTest.Sdk 4.4.0-preview.26381.1
  • .NET SDK 10.0.302, net10.0, Windows 11 x64

Also present on the released AzureDevOpsReport / Retry 2.3.3 + MSTest.Sdk 4.3.3, but only observable there after working around #10191.

Reproduced both via dotnet test and by invoking the test executable directly, and against a real Azure DevOps organisation as well as the stub endpoint in the attached repro.

Steps To Reproduce

A self-contained repro is attached (azdo-retry-repro.zip, ~6 KB). No Azure DevOps instance is required: fake-azdo.ps1 stands in for the three test REST endpoints the publisher calls, and returns a distinct run id for every POST /_apis/test/runs, so the number of runs created is directly observable.

pwsh ./run-repro.ps1

What it does:

  1. A test project on MSTest.Sdk with EnableMicrosoftTestingExtensionsAzureDevOpsReport and EnableMicrosoftTestingExtensionsRetry, containing one test that fails on the first attempt and passes on the second (gated on a marker file, since each attempt runs in a new process).
  2. Sets the four environment variables live publishing requires, pointed at the stub: TF_BUILD=True, SYSTEM_COLLECTIONURI=http://127.0.0.1:8130/, SYSTEM_TEAMPROJECT=FakeProj, SYSTEM_ACCESSTOKEN=fake-token, BUILD_BUILDID=999000.
  3. Runs --report-azdo --publish-azdo-test-results --retry-failed-tests 1.
  4. Prints every request the publisher made, and the resulting run count.

There is also a control case, described under Additional context:

pwsh ./run-repro.ps1 -SharedResultsDirectory

Expected behavior

One test run for the build, containing one result per test with its final outcome — matching what PublishTestResults@2 + AllowPtrToDetectTestRunRetryFiles produces.

Actual behavior

One run per attempt, each created and completed independently:

CREATE-RUN   -> assigned id 5001
POST-RESULTS /FakeProj/_apis/test/runs/5001/results
COMPLETE-RUN /FakeProj/_apis/test/runs/5001   body={"state":"Completed"}
CREATE-RUN   -> assigned id 5002
POST-RESULTS /FakeProj/_apis/test/runs/5002/results
COMPLETE-RUN /FakeProj/_apis/test/runs/5002   body={"state":"Completed"}

>>> test runs created: 2

while the same session reports locally:

Retry summary: Passed! after 2/2 attempts
  flaky: 1 (passed after retry)
Flaky tests:
  FailsOnFirstAttemptPassesOnRetry (failed -> passed)

Against a real Azure DevOps organisation, a build running a 4-test diagnostic class with one flaky test and --retry-failed-tests 1 produced:

Run Source Outcome counts
A --publish-azdo-test-results Failed 4
B --publish-azdo-test-results Failed 3, Passed 1
C PublishTestResults@2 Failed 3, Passed 1

Run C is a single run whose flaky test carries outcome=Passed, each result at revision=2 (updated by the second attempt). Runs A and B split the same information across two runs, and the recovered test stays Failed in A permanently.

Additional context

The coordination mechanism works — it just never engages for retry

The publisher writes its coordination files inside --results-directory:

<results-directory>/azdo-runid.<buildId>.json
<results-directory>/azdo-runid.<buildId>.owner
<results-directory>/azdo-runid.<buildId>.participant.<pid>.json

The file name is keyed by build id, implying build-wide scope, but its location gives it directory-wide scope. Two observations isolate this:

  • Two concurrent processes sharing one --results-directory (the -SharedResultsDirectory control in the repro): a single run is created, both processes POST .../runs/<id>/results into it, and it is completed once — >>> test runs created: 1. The mechanism does what it looks like it was built for.
  • Two concurrent processes with different --results-directory values, same BUILD_BUILDID: each writes its own azdo-runid.<buildId>.json, each declares itself owner, and each creates its own run.

With retry there are two independent reasons coordination cannot happen, so relocating the file alone would not be sufficient:

  1. The Retry extension places each attempt's output in its own subdirectory (<results-directory>/Retries/<id>/<attempt>/), so attempt 2 never sees attempt 1's coordination files.
  2. Attempts are sequential. Attempt 1's run is already PATCHed to Completed before attempt 2 starts, so there is no open run left to join. Completion would presumably need to be deferred until the retry orchestrator considers the session finished.

I could not find any command-line option to reuse or pin a run id, so there is no user-side workaround short of dropping --publish-azdo-test-results — which gives up the feature entirely.

Why it matters

Retrying flaky tests is a first-class Azure DevOps scenario for MTP, and it is documented as such in Microsoft.Testing.Platform Now Fully Supported in Azure DevOps — though that post covers the PublishTestResults@2 route rather than live publishing. Users who want progressive visibility in the Tests tab currently have to give up correct consolidation to get it. With live publishing enabled:

  • the Tests tab shows N runs per test project instead of one;
  • a test rescued by a retry is recorded as failed forever in the earlier run;
  • that per-attempt failure enters the historical test data which --report-azdo-flaky-history and --report-azdo-demote-known-flaky themselves query.

Note on labelling

Filing this as a bug rather than a feature request because the coordination mechanism exists, is keyed by build id, and demonstrably works when the results directory is shared — so this reads as a scoping defect rather than a missing capability. Happy to be re-labelled if retry awareness was never intended to be in scope.

azdo-retry-repro.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions