Skip to content

Commit

Permalink
Safe ApexTestContext dispose (#5082)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolev92 authored Mar 13, 2023
1 parent 0f3dbac commit ac7977c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/NuGet.Tests.Apex/NuGet.Tests.Apex/Apex/ApexTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading;
using Microsoft.Build.Utilities;
using Microsoft.Test.Apex.VisualStudio;
using Microsoft.Test.Apex.VisualStudio.Solution;
using NuGet.Common;
Expand Down Expand Up @@ -52,8 +54,20 @@ public ApexTestContext(VisualStudioHost visualStudio, ProjectTemplate projectTem
public void Dispose()
{
_logger.LogInformation("Test complete, closing solution.");

SolutionService.SaveAndClose();
for (int attempt = 1; attempt <= 3; attempt++)
{
try
{
SolutionService.SaveAndClose();
break;
}
catch (Exception ex)
{
_logger.LogInformation($"Failed to close VS on dispose. Attempt #{attempt}");
Thread.Sleep(TimeSpan.FromSeconds(3));
ExceptionUtilities.LogException(ex, _logger);
}
}
_pathContext.Dispose();
}
}
Expand Down

0 comments on commit ac7977c

Please sign in to comment.