Skip to content

Commit 1be0ed4

Browse files
committed
fix: harden windows sqlite test cleanup
1 parent 6bd5f26 commit 1be0ed4

4 files changed

Lines changed: 66 additions & 18 deletions

File tree

DotPilot.Tests/ChatSessions/Execution/AgentSessionServiceTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public sealed class AgentSessionServiceTests
1313
{
1414
private const int LegacyDefaultRole = 4;
1515
private const string LegacyEmptyCapabilitiesJson = "[]";
16+
private const int DeleteRetryCount = 20;
17+
private static readonly TimeSpan DeleteRetryDelay = TimeSpan.FromMilliseconds(250);
1618

1719
[Test]
1820
public async Task GetWorkspaceAsyncSeedsDefaultSystemAgentForANewStore()
@@ -646,7 +648,7 @@ private async ValueTask DisposeAsyncCore()
646648

647649
private static async Task DeleteDirectoryWithRetryAsync(string path)
648650
{
649-
for (var attempt = 0; attempt < 5; attempt++)
651+
for (var attempt = 0; attempt < DeleteRetryCount; attempt++)
650652
{
651653
if (!Directory.Exists(path))
652654
{
@@ -658,13 +660,13 @@ private static async Task DeleteDirectoryWithRetryAsync(string path)
658660
Directory.Delete(path, recursive: true);
659661
return;
660662
}
661-
catch (IOException) when (attempt < 4)
663+
catch (IOException) when (attempt < DeleteRetryCount - 1)
662664
{
663-
await Task.Delay(100);
665+
await Task.Delay(DeleteRetryDelay);
664666
}
665-
catch (UnauthorizedAccessException) when (attempt < 4)
667+
catch (UnauthorizedAccessException) when (attempt < DeleteRetryCount - 1)
666668
{
667-
await Task.Delay(100);
669+
await Task.Delay(DeleteRetryDelay);
668670
}
669671
}
670672
}

DotPilot.Tests/ChatSessions/Persistence/AgentSessionPersistenceTests.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace DotPilot.Tests.ChatSessions;
99

1010
public sealed class AgentSessionPersistenceTests
1111
{
12+
private const int DeleteRetryCount = 20;
13+
private static readonly TimeSpan DeleteRetryDelay = TimeSpan.FromMilliseconds(250);
1214
private static readonly JsonSerializerOptions HistorySerializerOptions = new()
1315
{
1416
TypeInfoResolver = new DefaultJsonTypeInfoResolver(),
@@ -82,7 +84,7 @@ await DrainAsync(
8284
}
8385
finally
8486
{
85-
DeleteDirectory(root);
87+
await DeleteDirectoryAsync(root);
8688
}
8789
}
8890

@@ -152,11 +154,28 @@ private static string CreateRootPath()
152154
Guid.NewGuid().ToString("N", System.Globalization.CultureInfo.InvariantCulture));
153155
}
154156

155-
private static void DeleteDirectory(string path)
157+
private static async Task DeleteDirectoryAsync(string path)
156158
{
157-
if (Directory.Exists(path))
159+
for (var attempt = 0; attempt < DeleteRetryCount; attempt++)
158160
{
159-
Directory.Delete(path, recursive: true);
161+
if (!Directory.Exists(path))
162+
{
163+
return;
164+
}
165+
166+
try
167+
{
168+
Directory.Delete(path, recursive: true);
169+
return;
170+
}
171+
catch (IOException) when (attempt < DeleteRetryCount - 1)
172+
{
173+
await Task.Delay(DeleteRetryDelay);
174+
}
175+
catch (UnauthorizedAccessException) when (attempt < DeleteRetryCount - 1)
176+
{
177+
await Task.Delay(DeleteRetryDelay);
178+
}
160179
}
161180
}
162181

DotPilot.Tests/Providers/Services/CodexCliTestScope.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace DotPilot.Tests.Providers;
55

66
internal sealed class CodexCliTestScope : IDisposable
77
{
8+
private const int DeleteRetryCount = 20;
9+
private static readonly TimeSpan DeleteRetryDelay = TimeSpan.FromMilliseconds(250);
810
private readonly string rootPath;
911
private readonly string? originalPath;
1012
private readonly string? originalHome;
@@ -54,10 +56,7 @@ public void Dispose()
5456
Environment.SetEnvironmentVariable("PATH", originalPath);
5557
Environment.SetEnvironmentVariable("HOME", originalHome);
5658
Environment.SetEnvironmentVariable("USERPROFILE", originalUserProfile);
57-
if (Directory.Exists(rootPath))
58-
{
59-
Directory.Delete(rootPath, recursive: true);
60-
}
59+
DeleteDirectoryWithRetry(rootPath);
6160

6261
disposed = true;
6362
}
@@ -232,4 +231,29 @@ private void WriteCommand(string commandName, string commandBody)
232231
UnixFileMode.OtherRead |
233232
UnixFileMode.OtherExecute);
234233
}
234+
235+
private static void DeleteDirectoryWithRetry(string path)
236+
{
237+
for (var attempt = 0; attempt < DeleteRetryCount; attempt++)
238+
{
239+
if (!Directory.Exists(path))
240+
{
241+
return;
242+
}
243+
244+
try
245+
{
246+
Directory.Delete(path, recursive: true);
247+
return;
248+
}
249+
catch (IOException) when (attempt < DeleteRetryCount - 1)
250+
{
251+
System.Threading.Thread.Sleep(DeleteRetryDelay);
252+
}
253+
catch (UnauthorizedAccessException) when (attempt < DeleteRetryCount - 1)
254+
{
255+
System.Threading.Thread.Sleep(DeleteRetryDelay);
256+
}
257+
}
258+
}
235259
}

DotPilot.Tests/Workspace/Services/StartupWorkspaceHydrationTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ namespace DotPilot.Tests.Workspace;
77
[NonParallelizable]
88
public sealed class StartupWorkspaceHydrationTests
99
{
10+
private const int DeleteRetryCount = 20;
11+
private static readonly TimeSpan DeleteRetryDelay = TimeSpan.FromMilliseconds(250);
12+
1013
[Test]
1114
public async Task EnsureHydratedAsyncWarmsProviderStatusForSubsequentWorkspaceReads()
1215
{
@@ -107,7 +110,7 @@ public ValueTask DisposeAsync()
107110

108111
private static async Task DeleteDirectoryWithRetryAsync(string path)
109112
{
110-
for (var attempt = 0; attempt < 5; attempt++)
113+
for (var attempt = 0; attempt < DeleteRetryCount; attempt++)
111114
{
112115
if (!Directory.Exists(path))
113116
{
@@ -119,13 +122,13 @@ private static async Task DeleteDirectoryWithRetryAsync(string path)
119122
Directory.Delete(path, recursive: true);
120123
return;
121124
}
122-
catch (IOException) when (attempt < 4)
125+
catch (IOException) when (attempt < DeleteRetryCount - 1)
123126
{
124-
await Task.Delay(100);
127+
await Task.Delay(DeleteRetryDelay);
125128
}
126-
catch (UnauthorizedAccessException) when (attempt < 4)
129+
catch (UnauthorizedAccessException) when (attempt < DeleteRetryCount - 1)
127130
{
128-
await Task.Delay(100);
131+
await Task.Delay(DeleteRetryDelay);
129132
}
130133
}
131134
}

0 commit comments

Comments
 (0)