From ff4d25f930e795559ae51b0e5c66d545fc91f280 Mon Sep 17 00:00:00 2001 From: Medeni Baykal <433724+Haplois@users.noreply.github.com> Date: Tue, 16 Feb 2021 10:43:21 +0100 Subject: [PATCH] Prefer agent temp directory if available. --- .../IntegrationTestBase.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 33f721e1e6..c9f8505b7a 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -725,14 +725,20 @@ protected string BuildMultipleAssemblyPath(params string[] assetNames) return string.Join(" ", assertFullPaths); } + /// + /// Creates an unique temporary directory for storing test results. + /// + /// + /// Path of the created directory. + /// 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; }