Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ await store.Maintenance.SendAsync(new PutIndexesOperation(new IndexDefinition
finally
{
await StopServer();
if (Directory.Exists(root))
{
FileUtils.DeleteDirectory(root, recursive: true, contentsOnly: false);
}
await TryDeleteDirectory(root, CancellationToken.None);
}

async Task StartServer()
Expand Down Expand Up @@ -143,9 +140,9 @@ async Task StopServer()
server.Kill(entireProcessTree: true);
}

await server.WaitForExitAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(15));
TestContext.Out.WriteLine(await standardOutput.WaitAsync(TimeSpan.FromSeconds(15)));
TestContext.Out.WriteLine(await standardError.WaitAsync(TimeSpan.FromSeconds(15)));
await server.WaitForExitAsync(CancellationToken.None).WaitAsync(TimeSpan.FromSeconds(15), cancellationToken);
await TestContext.Out.WriteLineAsync(await standardOutput.WaitAsync(TimeSpan.FromSeconds(15), cancellationToken));
await TestContext.Out.WriteLineAsync(await standardError.WaitAsync(TimeSpan.FromSeconds(15), cancellationToken));
}
finally
{
Expand All @@ -155,6 +152,30 @@ async Task StopServer()
}
}

// Cleanup of the temp folder must not fail the test; Directory.Delete keeps the path stable across retries.
static async Task TryDeleteDirectory(string root, CancellationToken cancellationToken, int attempts = 5, TimeSpan? delay = null)
{
var retryDelay = delay ?? TimeSpan.FromMilliseconds(500);
for (var attempt = 1; Directory.Exists(root); attempt++)
{
try
{
Directory.Delete(root, recursive: true);
return;
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
if (attempt == attempts)
{
await TestContext.Out.WriteLineAsync($"WARNING: Could not delete '{root}' after {attempts} attempts: {ex}");
return;
}

await Task.Delay(retryDelay * attempt, cancellationToken);
}
}
}

static async Task AssertDocumentAndIndex(IDocumentStore store, CancellationToken cancellationToken)
{
using var session = store.OpenAsyncSession();
Expand Down
Loading