From 8b008aa05ab3572edf8946b95cf3b1fe2a4a2cdc Mon Sep 17 00:00:00 2001 From: "Victor \"Nate\" Graf" Date: Wed, 3 Jan 2018 14:55:35 -0800 Subject: [PATCH] Fix size-on-disk benchmark to handle new CLI behavior (#15689) Add flag to ensure ensure the compiler server is not used so that the installation can be deleted successfully after the test. Additionally use a more robust deletion strategy to ensure files are deleted and the test does not fail spuriously due to random IO errors. --- tests/src/sizeondisk/sodbench/SoDBench.cs | 71 ++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 10 deletions(-) diff --git a/tests/src/sizeondisk/sodbench/SoDBench.cs b/tests/src/sizeondisk/sodbench/SoDBench.cs index 4c311ad..e6fca9d 100644 --- a/tests/src/sizeondisk/sodbench/SoDBench.cs +++ b/tests/src/sizeondisk/sodbench/SoDBench.cs @@ -223,7 +223,7 @@ namespace SoDBench Console.WriteLine($"** Using core libraries found at {options.CoreLibariesDirectory}"); s_corelibsDir = new DirectoryInfo(options.CoreLibariesDirectory); } - else + else { var coreroot = Environment.GetEnvironmentVariable("CORE_ROOT"); if (!String.IsNullOrEmpty(coreroot) && Directory.Exists(coreroot)) @@ -237,7 +237,7 @@ namespace SoDBench } } - PrintHeader("Installing Dotnet CLI"); + PrintHeader("** Installing Dotnet CLI"); s_dotnetExe = SetupDotnet(); } @@ -248,11 +248,11 @@ namespace SoDBench } Console.WriteLine($"** Path to dotnet executable: {s_dotnetExe.FullName}"); - - PrintHeader("Starting acquisition size test"); + + PrintHeader("** Starting acquisition size test"); var acquisition = GetAcquisitionSize(); - PrintHeader("Running deployment size test"); + PrintHeader("** Running deployment size test"); var deployment = GetDeploymentSize(); var root = new SizeReportingNode("Dotnet Total"); @@ -260,7 +260,7 @@ namespace SoDBench root.AddChild(deployment); var formattedStr = root.FormatAsCsv(); - + File.WriteAllText(options.OutputFilename, formattedStr); if (options.Verbose) @@ -270,8 +270,8 @@ namespace SoDBench { if (!s_keepArtifacts && s_sandboxDir != null) { - PrintHeader("Cleaning up sandbox directory"); - s_sandboxDir.Delete(true); + PrintHeader("** Cleaning up sandbox directory"); + DeleteDirectory(s_sandboxDir); s_sandboxDir = null; } } @@ -328,7 +328,7 @@ namespace SoDBench return result; } - + private static SizeReportingNode GetDeploymentSize() { // Write the NuGet.Config file @@ -370,7 +370,8 @@ namespace SoDBench ProcessStartInfo dotnetPublish = new ProcessStartInfo() { FileName = s_dotnetExe.FullName, - Arguments = $"publish -c Release --runtime {os} --output {publishDir.FullName}", // "out" is an arbitrary project name + // The UserSharedCompiler flag is set to false to prevent handles from being held that will later cause deletion of the installed SDK to fail. + Arguments = $"publish -c Release --runtime {os} --output {publishDir.FullName} /p:UseSharedCompilation=false", UseShellExecute = false, WorkingDirectory = deploymentSandbox.FullName }; @@ -677,6 +678,56 @@ namespace SoDBench private string _corelibsDir; private string _outputFilename = "measurement.csv"; } + + private static void DeleteDirectory(DirectoryInfo dir, uint maxWait=10000) + { + foreach (var subdir in dir.GetDirectories()) + { + DeleteDirectory(subdir); + } + + // Give it time to actually delete all the files + var files = dir.GetFiles(); + bool wait = true; + uint waitTime = 0; + while (wait) + { + wait = false; + + foreach (var f in files) + { + if (File.Exists(f.FullName)) + { + try + { + File.Delete(f.FullName); + } + catch (IOException) { if (waitTime > maxWait) throw; } + catch (UnauthorizedAccessException) { if (waitTime > maxWait) throw; } + + if (File.Exists(f.FullName)) + { + wait = true; + + // Print a message every 3 seconds if the thread is stuck + if (waitTime != 0 && waitTime % 3000 == 0) + { + Console.WriteLine($"Waiting to delete {f.FullName}"); + } + } + } + } + + // Try again in 100ms + if (wait) + { + Thread.Sleep(100); + waitTime += 100; + } + } + + Directory.Delete(dir.FullName); + } } // A simple class for escaping strings for CSV writing -- 2.7.4