Assert node directories are cleaned up.
MODIFY
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
@@ -16,24 +16,30 @@ namespace WalletWasabi.Tests.NodeBuilding
public class NodeBuilder : IDisposable
{
public static readonly AsyncLock Lock = new AsyncLock();
+ public static string WorkingDirectory { get; private set; }
public static async Task<NodeBuilder> CreateAsync([CallerMemberName]string caller = null, string version = "0.17.0")
{
using (await Lock.LockAsync())
{
- var directory = Path.Combine(SharedFixture.DataDir, caller);
+ WorkingDirectory = Path.Combine(SharedFixture.DataDir, caller);
version = version ?? "0.17.0";
var path = await EnsureDownloadedAsync(version);
+ await TryRemoveWorkingDirectoryAsync();
+ Directory.CreateDirectory(WorkingDirectory);
+ return new NodeBuilder(WorkingDirectory, path);
+ }
+ }
+
+ private static async Task TryRemoveWorkingDirectoryAsync()
+ {
try
{
- await IoHelpers.DeleteRecursivelyWithMagicDustAsync(directory);
+ await IoHelpers.DeleteRecursivelyWithMagicDustAsync(WorkingDirectory);
}
catch (DirectoryNotFoundException)
{
}
- Directory.CreateDirectory(directory);
- return new NodeBuilder(directory, path);
- }
}
private static async Task<string> EnsureDownloadedAsync(string version)
@@ -146,12 +152,19 @@ namespace WalletWasabi.Tests.NodeBuilding
public void Dispose()
{
- foreach (var node in Nodes)
+ foreach (CoreNode node in Nodes)
+ {
node.Kill();
- foreach (var disposable in _disposables)
+ }
+
+ foreach (IDisposable disposable in _disposables)
+ {
disposable.Dispose();
}
+ TryRemoveWorkingDirectoryAsync().GetAwaiter().GetResult();
+ }
+
private List<IDisposable> _disposables = new List<IDisposable>();
internal void AddDisposable(IDisposable group)

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -22,7 +22,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
public RegTestFixture()
{
- BackendNodeBuilder = NodeBuilder.CreateAsync().GetAwaiter().GetResult();
+ BackendNodeBuilder = NodeBuilder.CreateAsync(nameof(RegTestFixture)).GetAwaiter().GetResult();
BackendNodeBuilder.CreateNodeAsync().GetAwaiter().GetResult();
BackendNodeBuilder.StartAllAsync().GetAwaiter().GetResult();
BackendRegTestNode = BackendNodeBuilder.Nodes[0];

Assert node directories are cleaned up.