From 5097e2ae1f409ef6d15b0e2f34f4733abc2aeb6e Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 30 Jan 2019 06:24:18 +0500 Subject: [PATCH] Fix cleanup config files for the csharp xUnit tests (#8761) --- test/xUnit/csharp/test_PSConfiguration.cs | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/xUnit/csharp/test_PSConfiguration.cs b/test/xUnit/csharp/test_PSConfiguration.cs index eb140b0a3d..14821315d6 100644 --- a/test/xUnit/csharp/test_PSConfiguration.cs +++ b/test/xUnit/csharp/test_PSConfiguration.cs @@ -7,6 +7,7 @@ using System.Management.Automation; using System.Management.Automation.Configuration; using System.Management.Automation.Internal; using System.Reflection; +using System.Threading; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Xunit; @@ -263,14 +264,34 @@ namespace PSTests.Sequential public void CleanupConfigFiles() { - if (File.Exists(systemWideConfigFile)) - { - File.Delete(systemWideConfigFile); - } + var maxPause = 10; - if (File.Exists(currentUserConfigFile)) + while (maxPause-- != 0 && (File.Exists(systemWideConfigFile) || File.Exists(currentUserConfigFile))) { - File.Delete(currentUserConfigFile); + var pause = false; + + try + { + File.Delete(systemWideConfigFile); + } + catch (IOException) + { + pause = true; + } + + try + { + File.Delete(currentUserConfigFile); + } + catch (IOException) + { + pause = true; + } + + if (pause) + { + Thread.Sleep(5); + } } }