Skip to content

Commit b78db61

Browse files
Fix .NET test
Co-Authored-By: SteveSandersonMS <1101362+SteveSandersonMS@users.noreply.github.com>
1 parent e5409b0 commit b78db61

1 file changed

Lines changed: 41 additions & 8 deletions

File tree

dotnet/test/SessionFsTests.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task Should_Route_File_Operations_Through_The_Session_Fs_Provider()
4545
}
4646
finally
4747
{
48-
TryDeleteDirectory(providerRoot);
48+
await TryDeleteDirectoryAsync(providerRoot);
4949
}
5050
}
5151

@@ -84,7 +84,7 @@ public async Task Should_Load_Session_Data_From_Fs_Provider_On_Resume()
8484
}
8585
finally
8686
{
87-
TryDeleteDirectory(providerRoot);
87+
await TryDeleteDirectoryAsync(providerRoot);
8888
}
8989
}
9090

@@ -133,7 +133,7 @@ public async Task Should_Reject_SetProvider_When_Sessions_Already_Exist()
133133
}
134134
finally
135135
{
136-
TryDeleteDirectory(providerRoot);
136+
await TryDeleteDirectoryAsync(providerRoot);
137137
}
138138
}
139139

@@ -174,10 +174,11 @@ await session.SendAndWaitAsync(new MessageOptions
174174

175175
var fileContent = await ReadAllTextSharedAsync(GetStoredPath(providerRoot, session.SessionId, match.Groups[1].Value));
176176
Assert.Equal(suppliedFileContent, fileContent);
177+
await session.DisposeAsync();
177178
}
178179
finally
179180
{
180-
TryDeleteDirectory(providerRoot);
181+
await TryDeleteDirectoryAsync(providerRoot);
181182
}
182183
}
183184

@@ -222,7 +223,7 @@ await WaitForConditionAsync(async () =>
222223
}
223224
finally
224225
{
225-
TryDeleteDirectory(providerRoot);
226+
await TryDeleteDirectoryAsync(providerRoot);
226227
}
227228
}
228229

@@ -310,11 +311,43 @@ private static async Task<string> ReadAllTextSharedAsync(string path, Cancellati
310311
return await reader.ReadToEndAsync(cancellationToken);
311312
}
312313

313-
private static void TryDeleteDirectory(string path)
314+
private static async Task TryDeleteDirectoryAsync(string path)
314315
{
315-
if (Directory.Exists(path))
316+
if (!Directory.Exists(path))
317+
{
318+
return;
319+
}
320+
321+
var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(5);
322+
Exception? lastException = null;
323+
324+
while (DateTime.UtcNow < deadline)
325+
{
326+
try
327+
{
328+
if (!Directory.Exists(path))
329+
{
330+
return;
331+
}
332+
333+
Directory.Delete(path, recursive: true);
334+
return;
335+
}
336+
catch (IOException ex)
337+
{
338+
lastException = ex;
339+
}
340+
catch (UnauthorizedAccessException ex)
341+
{
342+
lastException = ex;
343+
}
344+
345+
await Task.Delay(100);
346+
}
347+
348+
if (lastException is not null)
316349
{
317-
Directory.Delete(path, recursive: true);
350+
throw lastException;
318351
}
319352
}
320353

0 commit comments

Comments
 (0)