Skip to content

Commit 787295c

Browse files
author
Christine Zhou
committed
Fixes error in file deletion after test finish
1 parent 0179067 commit 787295c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Tst/UnitTests/PCheckerLogGeneratorTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private void AssertLog(string generatedDir, string expectedDir)
7070
{
7171
Assert.Fail($"Test Failed \nMissing expected file in {generatedDir}: {file}");
7272
}
73+
Console.WriteLine("Test Succeeded");
7374
}
7475

7576
private static bool IsJsonContentIncluded(string generatedFilePath, string expectedFilePath)

Tst/UnitTests/TestAssertions.cs

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Threading;
34
using NUnit.Framework;
45
using UnitTests.Core;
56

@@ -26,14 +27,42 @@ public static void AssertTestCase(CompilerTestCase testCase)
2627
public static void SafeDeleteDirectory(DirectoryInfo toDelete)
2728
{
2829
var safeBase = new DirectoryInfo(Constants.SolutionDirectory);
30+
2931
for (var scratch = toDelete; scratch.Parent != null; scratch = scratch.Parent)
3032
{
31-
if (string.Compare(scratch.FullName, safeBase.FullName, StringComparison.InvariantCultureIgnoreCase) ==
32-
0)
33+
if (string.Compare(scratch.FullName, safeBase.FullName, StringComparison.InvariantCultureIgnoreCase) == 0)
3334
{
3435
if (toDelete.Exists)
3536
{
36-
toDelete.Delete(true);
37+
const int maxRetries = 5;
38+
const int delay = 200;
39+
40+
for (int i = 0; i < maxRetries; i++)
41+
{
42+
try
43+
{
44+
toDelete.Delete(true);
45+
return;
46+
}
47+
catch (IOException)
48+
{
49+
if (i == maxRetries - 1)
50+
{
51+
throw;
52+
}
53+
54+
Thread.Sleep(delay);
55+
}
56+
catch (UnauthorizedAccessException)
57+
{
58+
if (i == maxRetries - 1)
59+
{
60+
throw;
61+
}
62+
63+
Thread.Sleep(delay);
64+
}
65+
}
3766
}
3867

3968
return;

0 commit comments

Comments
 (0)