Skip to content

Commit 67c12dc

Browse files
author
Christine Zhou
committed
Fix safe delete failling windows tests
1 parent c2b6b70 commit 67c12dc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Tst/UnitTests/Runners/PCheckerRunner.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public int RunCheckerInProcess(CheckerConfiguration configuration, string testAs
220220
{
221221
lock (CheckerLock)
222222
{
223+
var exitCode = 0;
223224
var context = new AssemblyLoadContext($"ALC_{Guid.NewGuid():N}", isCollectible: true);
224225
Assembly assembly = context.LoadFromAssemblyPath(testAssemblyPath);
225226

@@ -239,14 +240,14 @@ public int RunCheckerInProcess(CheckerConfiguration configuration, string testAs
239240
if (bug != null)
240241
{
241242
stdout += bug;
242-
return 1;
243+
exitCode = 1;
243244
}
244245

245246
context.Unload();
246247
GC.Collect();
247248
GC.WaitForPendingFinalizers();
248249

249-
return 0;
250+
return exitCode;
250251
}
251252
}
252253
catch (Exception ex)

Tst/UnitTests/TestAssertions.cs

Lines changed: 17 additions & 1 deletion
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

@@ -33,7 +34,22 @@ public static void SafeDeleteDirectory(DirectoryInfo toDelete)
3334
{
3435
if (toDelete.Exists)
3536
{
36-
toDelete.Delete(true);
37+
for (int i = 0; i < 5; i++)
38+
{
39+
try
40+
{
41+
toDelete.Delete(true);
42+
break;
43+
}
44+
catch (IOException)
45+
{
46+
Thread.Sleep(200);
47+
}
48+
catch (UnauthorizedAccessException)
49+
{
50+
Thread.Sleep(200);
51+
}
52+
}
3753
}
3854

3955
return;

0 commit comments

Comments
 (0)