Skip to content

Commit

Permalink
Prefer agent temp directory if available.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Feb 16, 2021
1 parent 3d0ed61 commit ff4d25f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,20 @@ protected string BuildMultipleAssemblyPath(params string[] assetNames)
return string.Join(" ", assertFullPaths);
}

/// <summary>
/// Creates an unique temporary directory for storing test results.
/// </summary>
/// <returns>
/// Path of the created directory.
/// </returns>
protected static string GetResultsDirectory()
{
var directoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
// AGENT_TEMPDIRECTORY is AzureDevops variable, which is set to path
// that is cleaned up after every job. This is preferable to use over
// just the normal temp.
var temp = Environment.GetEnvironmentVariable("AGENT_TEMPDIRECTORY") ?? Path.GetTempPath();
var directoryPath = Path.Combine(temp, Guid.NewGuid().ToString("n"));
Directory.CreateDirectory(directoryPath);

return directoryPath;
}
Expand Down

0 comments on commit ff4d25f

Please sign in to comment.