Implement cleanup after regtests
MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1590,8 +1590,7 @@ namespace WalletWasabi.Tests
var mempoolTxId = rpc.SendToAddress(new Key().PubKey.GetSegwitAddress(network), Money.Coins(1));
var folder = Path.Combine(SharedFixture.DataDir, nameof(CcjCoordinatorCtorTestsAsync));
- await IoHelpers.DeleteRecursivelyWithMagicDustAsync(folder);
- Directory.CreateDirectory(folder);
+
var cjfile = Path.Combine(folder, $"CoinJoins{network}.txt");
File.WriteAllLines(cjfile, new[]{
coinbaseTxId.ToString(),
@@ -1607,8 +1606,6 @@ namespace WalletWasabi.Tests
Assert.Contains(mempoolTxId.ToString(), txIds);
Assert.DoesNotContain(offchainTxId.ToString(), txIds);
- await IoHelpers.DeleteRecursivelyWithMagicDustAsync(folder);
- Directory.CreateDirectory(folder);
File.WriteAllLines(cjfile, new[]{
coinbaseTxId.ToString(),
"This line is invalid (the file is corrupted)",
@@ -2741,11 +2738,11 @@ namespace WalletWasabi.Tests
var chaumianClient2 = new CcjClient(network, coordinator.RsaKey.PubKey, keyManager2, new Uri(RegTestFixture.BackendEndPoint));
// 6. Create wallet service.
- var workDir = Path.Combine(SharedFixture.DataDir, nameof(CoinJoinMultipleRoundTestsAsync));
+ var workDir = Path.Combine(SharedFixture.DataDir, nameof(CoinJoinMultipleRoundTestsAsync), "workDir");
var wallet = new WalletService(keyManager, indexDownloader, chaumianClient, memPoolService, nodes, workDir);
wallet.NewFilterProcessed += Wallet_NewFilterProcessed;
- var workDir2 = Path.Combine(SharedFixture.DataDir, $"{nameof(CoinJoinMultipleRoundTestsAsync)}2");
+ var workDir2 = Path.Combine(SharedFixture.DataDir, $"{nameof(CoinJoinMultipleRoundTestsAsync)}", "workDir2");
var wallet2 = new WalletService(keyManager2, indexDownloader2, chaumianClient2, memPoolService2, nodes2, workDir2);
// Get some money, make it confirm.

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
using Microsoft.AspNetCore.Hosting;
using NBitcoin;
using System;
+using System.IO;
+using System.Linq;
+using System.Reflection;
using System.Threading.Tasks;
using WalletWasabi.Backend;
using WalletWasabi.Logging;
using WalletWasabi.Models.ChaumianCoinJoin;
using WalletWasabi.Tests.NodeBuilding;
+using Xunit;
namespace WalletWasabi.Tests.XunitConfiguration
{
@@ -48,6 +52,20 @@ namespace WalletWasabi.Tests.XunitConfiguration
var delayTask = Task.Delay(3000);
Task.WaitAny(delayTask, hostInitializationTask); // Wait for server to initialize (Without this OSX CI will fail)
+ string[] methods = GetMethodNames();
+ foreach (string name in methods)
+ {
+ string folder = Path.Combine(SharedFixture.DataDir, name);
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(folder).GetAwaiter().GetResult();
+ Directory.CreateDirectory(folder);
+ }
+ }
+
+ private static string[] GetMethodNames()
+ {
+ return typeof(RegTests).GetMethods().Where(x => !x.IsConstructor && x.IsPublic).Select(x => x.Name)
+ .Except(typeof(object).GetMethods().Select(x => x.Name))
+ .Distinct().ToArray();
}
public void Dispose()
@@ -58,6 +76,13 @@ namespace WalletWasabi.Tests.XunitConfiguration
BackendHost?.Dispose();
BackendRegTestNode?.Kill(cleanFolder: true);
BackendNodeBuilder?.Dispose();
+
+ string[] methods = GetMethodNames();
+ foreach (string name in methods)
+ {
+ string folder = Path.Combine(SharedFixture.DataDir, name);
+ IoHelpers.DeleteRecursivelyWithMagicDustAsync(folder).GetAwaiter().GetResult();
+ }
}
}
}

Implement cleanup after regtests