Question

In a custom TFS 2012 workflow I'm using the following code snippet:

IBuildDetail buildDetail = context.GetValue(BuildDetail);
var testManagementService = TfsTeamProjectCollectionFactory
                .GetTeamProjectCollection(new Uri("http://tfs:8080/tfs/Sandbox"))
                .GetService<ITestManagementService>();

var buildCoverages = testManagementService
                .GetTeamProject(buildDetail.TeamProject)
                .CoverageAnalysisManager
                .QueryBuildCoverage(buildDetail.Uri.ToString(), CoverageQueryFlags.Modules);

Code coverage is being executed on the build correctly and the 'Build Summary' for the build contains:

> 2 binaries instrumented - 89% of all code blocks covered
    fooTests.dll - 99% of 479 code blocks covered
    foo.exe - 74% of 347 code blocks covered

For testing purposes the custom activity is the last activity in the workflow after 'Check-in gated changes'. During the build the buildCoverages variable contains a 0 length array. Any idea why this is? Do the coverage results get submitted back to TFS asynchronously, post the build completing? Is the build in a 'transaction' and the above code operating without visibility to the in progress build? Any help most appreciated.

Was it helpful?

Solution

I'm not sure why (there could be a myriad of reasons) but the availability of the coverage during the build workflow via this interface is not synchronous with the workflow. Adding a delay loop

do
{
    buildCoverages = testManagementService
            .GetTeamProject(buildDetail.TeamProject)
            .CoverageAnalysisManager
            .QueryBuildCoverage(buildDetail.Uri.ToString(), CoverageQueryFlags.Modules);
} while(buildCoverages.Length == 0 && retryDelay())

around this code assures (so far within a few seconds) the availability of the build coverages array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top