diff --git a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs index 9267c0f99..e5f200486 100644 --- a/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs +++ b/ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs @@ -329,8 +329,8 @@ namespace ICSharpCode.Decompiler.Tests Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile); - File.Delete(decompiledCodeFile); - File.Delete(decompiledOutputFile.PathToAssembly); + Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile)); + Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly)); } finally { if (outputFile != null) outputFile.TempFiles.Delete(); @@ -354,8 +354,8 @@ namespace ICSharpCode.Decompiler.Tests Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile); - File.Delete(decompiledCodeFile); - File.Delete(decompiledOutputFile.PathToAssembly); + Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile)); + Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly)); } finally { if (outputFile != null) outputFile.TempFiles.Delete(); @@ -375,9 +375,9 @@ namespace ICSharpCode.Decompiler.Tests decompiledOutputFile = Tester.CompileCSharp(decompiledCodeFile, options); Tester.RunAndCompareOutput(testFileName, outputFile, decompiledOutputFile.PathToAssembly, decompiledCodeFile); - - File.Delete(decompiledCodeFile); - File.Delete(decompiledOutputFile.PathToAssembly); + + Tester.RepeatOnIOError(() => File.Delete(decompiledCodeFile)); + Tester.RepeatOnIOError(() => File.Delete(decompiledOutputFile.PathToAssembly)); } finally { if (decompiledOutputFile != null) decompiledOutputFile.TempFiles.Delete(); diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs index 08a037e95..e09cecda9 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.VB.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.VisualBasic; diff --git a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs index 82b98f3db..dfe0d7cb2 100644 --- a/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs +++ b/ICSharpCode.Decompiler.Tests/Helpers/Tester.cs @@ -518,5 +518,21 @@ namespace ICSharpCode.Decompiler.Tests.Helpers Assert.Fail(b.ToString()); } } + + internal static void RepeatOnIOError(Action action, int numTries = 5) + { + for (int i = 0; i < numTries - 1; i++) { + try { + action(); + return; + } catch (IOException) { + } catch (UnauthorizedAccessException) { + // potential virus scanner problem + } + Thread.Sleep(10); + } + // If the last try still fails, don't catch the exception + action(); + } } }