Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection getting disposed #5039

Merged
merged 10 commits into from
Nov 26, 2024
Merged
Next Next commit
Update ResultsCommandExtension.cs
  • Loading branch information
KathanS authored Nov 12, 2024
commit db3bf782064ebf99a6493f7d8fad22ba9ba5c7dc
20 changes: 12 additions & 8 deletions src/Agent.Worker/TestResults/ResultsCommandExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ private PublishOptions GetPublishOptions()
private async Task PublishTestRunDataAsync(string teamProject, TestRunContext testRunContext)
{
bool isTestRunOutcomeFailed = false;

_telemetryProperties.Add("UsePublishTestResultsLib", _publishTestResultsLibFeatureState);
using (var connection = WorkerUtilities.GetVssConnection(_executionContext))
var connection = WorkerUtilities.GetVssConnection(_executionContext);

try
{

//This check is to determine to use "Microsoft.TeamFoundation.PublishTestResults" Library or the agent code to parse and publish the test results.
if (_publishTestResultsLibFeatureState)
{
var publisher = _executionContext.GetHostContext().GetService<ITestDataPublisher>();
publisher.InitializePublisher(_executionContext, teamProject, connection, _testRunner);

if (_enableAzureTestPlanFeatureState && !_testCaseResults.IsNullOrEmpty() && !_testPlanId.IsNullOrEmpty())
{
isTestRunOutcomeFailed = await publisher.PublishAsync(testRunContext, _testResultFiles, _testCaseResults, GetPublishOptions(), _executionContext.CancellationToken);
Expand All @@ -335,22 +335,26 @@ private async Task PublishTestRunDataAsync(string teamProject, TestRunContext te
{
var publisher = _executionContext.GetHostContext().GetService<ILegacyTestRunDataPublisher>();
publisher.InitializePublisher(_executionContext, teamProject, connection, _testRunner, _publishRunLevelAttachments);

isTestRunOutcomeFailed = await publisher.PublishAsync(testRunContext, _testResultFiles, _runTitle, _executionContext.Variables.Build_BuildId, _mergeResults);
}

if (isTestRunOutcomeFailed && _failTaskOnFailedTests)
{
_executionContext.Result = TaskResult.Failed;
_executionContext.Error(StringUtil.Loc("FailedTestsInResults"));
}

await PublishEventsAsync(connection);
if (_triggerCoverageMergeJobFeatureState)
{
TriggerCoverageMergeJob(_testResultFiles, _executionContext);
}
}
finally
{
connection?.Dispose();
}
}

// Queue code coverage merge job if code coverage attachments are published to avoid BQC timeout.
Expand Down