azure-pipelines-tasks: VS Test Retry Has Stopped Working On Azure Pipeline

We’ve noticed in the last few days that a couple of our VS Test runs no longer retries on failures, and upon retry, it is unable to find the name spaces for those tests.
The tests are written in SpecFlow 3.9.74. We were using an old Test SDK (16.5) but on upgrade to 17.3.2, we still have this issue. We are running on Windows-Latest (2022). Tried with 2019 but had the same issue as well. We did not use VS Installer first, but I’ve tried with that, and we still have the issue where the retries no longer work

We run using the below YAML code: - task: VSTest@2 displayName: 'VsTest - testAssemblies' inputs: testAssemblyVer2: | **\JourneyTests.dll !**\*TestAdapter.dll !**\obj\** rerunFailedTests: true rerunFailedThreshold: 35 rerunMaxAttempts: 2 testRunTitle: '${{ parameters.Environment }} - Journey Tests' searchFolder: $(PIPELINE.WORKSPACE)\${{ parameters.PipelineResource }}\${{ parameters.ArtifactResource }} ${{ if ne(parameters.CategoryFilter, '') }}: testFiltercriteria: ${{ parameters.CategoryFilter }} env: ${{ if eq(parameters.UseMocks, true) }}: UseMocks: true ${{ else }}: UseMocks: false

In our logs, you can see it start the retry attempt, then fail as it is unable to match the name space

No test matches the given testcase filter FullyQualifiedName=JourneyTests.Features.HappyPathFeature.New user sign up journey.

This seems to have changed sometime between Tuesday of this week and Wednesday of this week. We run these tests on a schedule, so there was no code change between the runs on Tuesday and Wednesday.

Tue: Microsoft (R) Test Execution Command Line Tool Version 17.3.0-preview-20220626-01 (x64) [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.5+1caef2f33e (64-bit .NET Core 3.1.29) DTA Execution Host 19.210.32906.4

Wed: Microsoft (R) Test Execution Command Line Tool Version 17.3.0-preview-20220626-01 (x64) [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.5+1caef2f33e (64-bit .NET Core 3.1.29) DTA Execution Host 19.204.32418.1

Environment

  • Azure Pipelines
  • Windows 2022

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 10
  • Comments: 78 (27 by maintainers)

Most upvoted comments

Any update on this?

We have picked this bug for fix for upcoming sprint. I will inform once this is fixed.

As for a workaround, referencing the task version explicitly in the YAML file works, i.e. instead of just

    - task: VSTest@2
# or
    - task: VSTest@3

write

    - task: VSTest@2.205.0  # Using a full version temporarily to fix https://github.com/microsoft/azure-pipelines-tasks/issues/16990
# or
    - task: VSTest@3.205.0  # Using a full version temporarily to fix https://github.com/microsoft/azure-pipelines-tasks/issues/16990

Any update?

@vinayakmsft - any updates?

This is caused by a VSTest task upgrade from 2.205.0 to 2.210.0, done in #16853. It broke handling of tests with a different/custom display name and fully qualified name.

It will not help to update or change the versions of Visual Studio, testing framework or build agents. The VSTest@2/3 tasks need to be fixed (they reference a newer dependency which broke backwards compatibility).


When tests are simply run without extra options, VSTest.Console.exe is executed directly, the test results are published by the agent to the pipeline and that’s it.

However, if retries are enabled, a closed source “DtaExecutionHost” component is put in between. It runs VSTest.Console.exe potentially multiple times, parses the output .trx files itself, publishes that to the pipeline, determines the failing ones back through some REST API, handles the reruns, and so on.

This DtaExecutionHost got upgraded from 19.204.32418.1 to 19.210.32906.4 during the upgrade of the VSTest ADO task. The way how a dependency “Microsoft.TeamFoundation.TestClient.PublishTestResults.dll” inside the DtaExecutionHost parses the .trx files changed, and it broke the test reruns for customers.


For example, for a parametrized test case with the following definition

    [TestMethod]
    [DataTestMethod]
    [DataRow("One")]
    [DataRow("Two")]
    public void TestMethod(string Parameter)

The .trx file will have something like this:

  <TestDefinitions>
    <UnitTest name="TestMethod (One)"
               storage="c:\whatever\bin\debug\net6.0\testproject.dll"
               id="df932f1e-0bdf-4fd8-b4e0-1d20f4f13e98">
      <Execution id="101c7677-781f-43dd-9240-442df2afb88d" />
      <TestMethod codeBase="C:\Whatever\bin\Debug\net6.0\TestProject.dll"
               adapterTypeName="executor://mstestadapter/v2"
               className="Example.Project.Tests.TestClass"
               name="TestMethod" />
    </UnitTest>

Note the <UnitTest name="TestMethod (One)" ... has spaces and parentheses. But <TestMethod className="className="Example.Project.Tests.TestClass" name="TestMethod" ... does not.

Now the change in DtaExecutionHost:

--- before\Microsoft.TeamFoundation.TestClient.PublishTestResults-19.204.32418.1\Microsoft.TeamFoundation.TestClient.PublishTestResults\TrxResultParser.cs	Mon Oct 03 16:56:16 2022
+++ after\Microsoft.TeamFoundation.TestClient.PublishTestResults-19.210.32906.4\Microsoft.TeamFoundation.TestClient.PublishTestResults\TrxResultParser.cs	Mon Oct 03 16:55:38 2022
@@ -229,9 +229,9 @@
 			}
 			XmlNode testResultNode = definitionNode.SelectSingleNode("./TestMethod");
 			string automatedTestName = null;
-			if (testResultNode?.Attributes["className"] != null && testResultNode.Attributes["name"] != null)
+			if (testResultNode?.Attributes["className"] != null && (definitionNode.Attributes["name"]?.Value != null || testResultNode.Attributes["name"].Value != null))
 			{
-				string testCaseName = testResultNode.Attributes["name"].Value;
+				string testCaseName = ((definitionNode.Attributes["name"]?.Value == null) ? testResultNode.Attributes["name"].Value : definitionNode.Attributes["name"].Value);
 				string className = testResultNode.Attributes["className"].Value;
 				automatedTestName = ((testCaseName.StartsWith(className) && testCaseName.Contains(".")) ? testCaseName : string.Join(".", className, testCaseName));
 				if (_chutzpahTestFileExtensions.Contains(storageExtension?.Trim(), StringComparer.OrdinalIgnoreCase) && !string.IsNullOrEmpty(storageFileName))

This starts overriding the test case name from the name attribute on the <UnitTest/>. Before: automatedTestName = TestMethod["className'"] + "." + TestMethod["name"] After: automatedTestName = TestMethod["className"] + "." + (UnitTest["name"] ?? TestMethod["name"])

In practice, instead of making the rerun as: VSTest.Console.exe /TestCaseFilter:"FullyQualifiedName=Example.Project.Tests.TestClass.TestMethod" and unfortunately rerunning all variants of the test, but at least working, it now results in: VSTest.Console.exe /TestCaseFilter:"FullyQualifiedName=Example.Project.Tests.TestClass.TestMethod (One)" Which does not work at all.

It is wrong for two reasons:

  1. The paretheses are not escaped correctly Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.
  2. It is not a valid FullyQualifiedName, that needs really just the method FQN. Comparing the display name or whatever would need a completely different filter being made.

For Ben above, it is even simpler - just a test display name with spaces, resulting in FullyQualifiedName=JourneyTests.Features.HappyPathFeature.New user sign up journey instead of a proper method name. Again resulting in no test being found to retry.

@alexButcherMP yeah Bhavshuk is looking at it

Image

I will have a look at this issue and reply back by with actions planned for it in upcoming week.

Tagging @virekumar @bhaveshbhati @vmapetr @DmitriiBobreshev as you’ve made commits in the last month. Would be grateful if you could take a look at this issue.

Hey @dogirala, are there any updates on this?

The issue still exist in 2.240.1 I am not sure if it’s related to the same issue but it look like test result files .trx is not found in fact the file exist but under different name

2024-07-06T01:29:06.7861490Z ##[error]Test Run Failed. 2024-07-06T01:29:06.7872567Z Total time: 2.7576 Hours 2024-07-06T01:29:06.9003794Z Vstest.console.exe exited with code 1. 2024-07-06T01:29:06.9004211Z **************** Completed test execution ********************* 2024-07-06T01:29:06.9138261Z Test results files: C:\Workspace\vsts-agent-win-x64-2.175.2_work_tempTestResults\TestQAAdmin_FSTestQA1QAVM_2024-07-05_18_43_41.trx 2024-07-06T01:29:08.0904084Z Created test run: 24571 2024-07-06T01:29:08.0905939Z Publishing test results: 773 2024-07-06T01:29:08.2283146Z Publishing test results to test run ‘24571’. 2024-07-06T01:29:08.2310527Z TestResults To Publish 773, Test run id:24571 2024-07-06T01:29:08.2405898Z Test results publishing 773, remaining: 0. Test run id: 24571 2024-07-06T01:29:16.1785969Z Published test results: 773 2024-07-06T01:29:16.1792053Z Publishing Attachments: 1 2024-07-06T01:29:16.6797433Z Failed tests: 33; Total tests: 773; 2024-07-06T01:29:16.7775678Z Total failed tests as returned by TCM: 33. 2024-07-06T01:29:16.7783700Z Found 1 filtered test case sources. 2024-07-06T01:29:16.8427013Z **************** Rerunning failed tests for Test run 24571 ********************* 2024-07-06T01:29:16.8427619Z Max attempts: 3; Current attempt: 1; Failed test cases threshold: 80; Failed test cases max limit: 0 … 2024-07-06T01:29:16.8974096Z “C:\Workspace\vsts-agent-win-x64-2.175.2_work\r1\a_SFApp Forms - Regression - Build\DropRegressionBuild\Project\TestProj\bin\Debug\TestProj.dll” 2024-07-06T01:29:16.8974719Z /Settings:“C:\Workspace\vsts-agent-win-x64-2.175.2_work_temp\lngbmr0khhl.tmp.runsettings” 2024-07-06T01:29:16.8975106Z /InIsolation 2024-07-06T01:29:16.8975313Z /Logger:“trx” 2024-07-06T01:29:16.8975624Z /TestAdapterPath:“C:\Workspace\vsts-agent-win-x64-2.175.2_work\r1\a” 2024-07-06T01:29:17.3201567Z Starting test execution, please wait… 2024-07-06T01:29:17.4869939Z A total of 1 test files matched the specified pattern. 2024-07-06T01:29:18.4763470Z NUnit Adapter 4.5.0.0: Test execution started 2024-07-06T01:29:18.5127857Z Running selected tests in C:\Workspace\vsts-agent-win-x64-2.175.2_work\r1\a_SFApp Forms - Regression - Build\DropRegressionBuild\Project\TestProj\bin\Debug\TestProj.dll 2024-07-06T01:29:19.1204574Z NUnit3TestExecutor discovered 0 of 0 NUnit test cases using Current Discovery mode, Explicit run 2024-07-06T01:29:19.2765187Z NUnit Adapter 4.5.0.0: Test execution complete 2024-07-06T01:29:19.3983320Z No test matches the given testcase filter (ClassName=TestProj.Z_SingleObject&Name=N_TC_BR_FB_29_02)|(ClassName=TestProj.Z_Lookup&Name=N_TC_BR_Lookup_14)|(ClassName=TestProj.Z_FormDashboard&Name=N_TC_BR_FD_02)|(ClassName=TestProj.Z_FlexibleFormControls&Name=N_TC_BR_FFC_39)|(ClassName=TestProj.Z_Con... in C:\Workspace\vsts-agent-win-x64-2.175.2_work\r1\a_SFApp Forms - Regression - Build\DropRegressionBuild\Project\TestProj\bin\Debug\TestProj.dll 2024-07-06T01:29:19.5073113Z Results File: C:\Workspace\vsts-agent-win-x64-2.175.2_work_tempTestResults\TestQAAdmin_FSTestQA1QAVM_2024-07-05_21_29_19.trx 2024-07-06T01:29:19.5328203Z Vstest.console.exe exited with code 0. 2024-07-06T01:29:19.5328700Z **************** Completed test execution ********************* 2024-07-06T01:29:19.5377712Z Test results files: C:\Workspace\vsts-agent-win-x64-2.175.2_work_tempTestResults\TestQAAdmin_FSTestQA1QAVM_2024-07-05_21_29_19.trx 2024-07-06T01:29:19.5402694Z No Result Found to Publish ‘C:\Workspace\vsts-agent-win-x64-2.175.2_work_tempTestResults\TestQAAdmin_FSTestQA1QAVM_2024-07-05_21_29_19.trx’. 2024-07-06T01:29:19.5403181Z Updating test results: 0 2024-07-06T01:29:19.5824051Z Publishing test results to test run ‘24571’. 2024-07-06T01:29:19.8174325Z TestResults To Publish 0, Test run id:24571 2024-07-06T01:29:19.8174800Z Updated test results: 0 2024-07-06T01:29:19.8175103Z Publishing Attachments: 1 2024-07-06T01:29:19.9454973Z ##[error]Error occurred while publishing test results : System.Exception: No tests were discovered while attempting to rerun failed tests. This is likely to happen if these tests are xunit or nunit datadriven/parameterized tests or tests with custom display names with spaces or special characters which are not supported with rerun. Please reach out to us at https://github.com/microsoft/azure-pipelines-tasks/issues if you are hitting this for tests other than the ones mentioned before. 2024-07-06T01:29:20.0541149Z Execution Result Code 1 is non zero, checking for failed results 2024-07-06T01:29:20.1595447Z Completed TestExecution Model…

Hi @dogirala, no worries. Unfortunately, I do not know the hostname of our Azure DevOps instance, region is West Europe.

@SeMuell, I’ve tried in local it is working as expected without the customBatchSize. image, will update here once vstest is deployed

I clarified this with @dogirala and the problem turned out to be in our custom ITestDataSource::GetDisplayName() implementation, which was formatting parameterized test names as MethodName(parameters) (i.e. without a space), which was different from e.g. the standard [DataTestMethod], which uses MethodName (parameters) (i.e. with a space before the opening parenthesis).

After changing the display name to match the usual style, everything works fine and the VSTest task correctly retries only the single relevant test case (by using a combined, correctly escaped filter, e.g. (FullyQualifiedName=Trouter.FunctionalTests.Test_ReconnectTtl_LongPoll&Name=Test_ReconnectTtl_LongPoll \(v3\))). Thanks for the fix!

Adding the observations from the above error, for dynamic tests or tests with custom displayname, please follow the same naming as standard [DataTestMethod] to resolve the above issue. Something like the below overload should work. Please reach out if issue is still observed

’

   public string GetDisplayName(MethodInfo methodInfo, object[] data)
    {
        if (data != null)
        {
            var testParamString = new StringBuilder();
            testParamString.Append(methodInfo.Name);

            testParamString.Append(' (');
            var methodParameters = methodInfo.GetParameters();
            for (int i = 0; i < methodParameters.Length; i++)
            {
                testParamString.Append(data[i]);
                testParamString.Append(',');
            }
            testParamString.Length--;
            testParamString.Append(')');

            return testParamString.ToString();
        }

        return methodInfo.Name;
    }

’

Thanks for the update. The new task version does not seem to have the desired effect on our pipeline.

Before (v2.224.0):

2023-08-16T08:49:17.0628419Z Task : Visual Studio Test
2023-08-16T08:49:17.0628738Z Version : 2.224.0 
...
2023-08-16T08:49:17.9948378Z DtaExecutionHost version 19.210.32906.4. 
...
2023-08-16T09:06:29.5685456Z Failed Test_DisconnectOnLargeMessage(v4) [39 s]
...
2023-08-16T09:10:37.8506695Z **************** Rerunning failed tests for Test run 326350859 ********************* 
2023-08-16T09:10:37.8948952Z vstest.console.exe /TestCaseFilter:
        "FullyQualifiedName=Trouter.FunctionalTests.TrouterNativeNetClientFunctionalTest.Test_DisconnectOnLargeMessage(v4)"
...
2023-08-16T09:10:39.6810636Z ##[error]Incorrect format for TestCaseFilter Missing Operator '|' or '&'.
                             Specify the correct format and try again. Note that the incorrect format
                             can lead to no test getting executed. 

After (v2.227.0):

2023-08-24T19:39:22.9042215Z Task : Visual Studio Test
2023-08-24T19:39:22.9042542Z Version : 2.227.0 
...
2023-08-24T19:39:28.8259497Z DtaExecutionHost version 19.226.34002.2. 
...
2023-08-24T19:54:38.0774500Z Failed Test_MessageStore_TrySyncMode(v3) [13 s] 
2023-08-24T19:54:45.0069644Z Failed Test_MessageStore_TrySyncMode(v4) [6 s] 
...
2023-08-24T20:00:32.8905690Z **************** Rerunning failed tests for Test run 327331990 ********************* 
2023-08-24T20:00:32.9432344Z vstest.console.exe /TestCaseFilter:
        "(FullyQualifiedName=Trouter.FunctionalTests.TrouterNativeNetClientFunctionalTest.Test_MessageStore_TrySyncMode(v4))
        |(FullyQualifiedName=Trouter.FunctionalTests.TrouterNativeNetClientFunctionalTest.Test_MessageStore_TrySyncMode(v3))"
...
2023-08-24T20:00:34.9557818Z ##[error]Incorrect format for TestCaseFilter Missing Operator '|' or '&'.
                             Specify the correct format and try again. Note that the incorrect format
                             can lead to no test getting executed. 

Should be fixed in VSTest@2.225.0 after #18760 gets merged

We have taken this as our work item , maybe by next week we will update

One month later, what is the status here?

Yeah I also didn’t know that version pinning worked to the last digit, very fortunate and useful. Thanks for the confirmation from elsewhere!