Use better async practices
MODIFY
WalletWasabi.Tests/NodeBuilding/CoreNode.cs
WalletWasabi.Tests/NodeBuilding/CoreNode.cs
using NBitcoin.DataEncoders;
using NBitcoin.Protocol;
using NBitcoin.RPC;
+using Nito.AsyncEx;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -91,7 +92,7 @@ namespace WalletWasabi.Tests.NodeBuilding
};
config.Import(ConfigParameters);
File.WriteAllText(Config, config.ToString());
- lock (_l)
+ using (await _l.LockAsync())
{
_process = Process.Start(new FileInfo(_Builder.BitcoinD).FullName, "-conf=bitcoin.conf" + " -datadir=" + DataDir + " -debug=1");
State = CoreNodeState.Starting;
@@ -144,15 +145,15 @@ namespace WalletWasabi.Tests.NodeBuilding
}
}
- private readonly object _l = new object();
+ private readonly AsyncLock _l = new AsyncLock();
- public void Kill(bool cleanFolder = true)
+ public async Task KillAsync(bool cleanFolder = true)
{
- lock (_l)
+ using (await _l.LockAsync())
{
try
{
- CreateRpcClient().Stop();
+ await CreateRpcClient().StopAsync();
if (!_process.WaitForExit(20000))
{
//log this
@@ -165,7 +166,7 @@ namespace WalletWasabi.Tests.NodeBuilding
}
if (cleanFolder)
{
- IoHelpers.DeleteRecursivelyWithMagicDustAsync(Folder).GetAwaiter().GetResult();
+ await IoHelpers.DeleteRecursivelyWithMagicDustAsync(Folder);
}
}

MODIFY
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
WalletWasabi.Tests/NodeBuilding/NodeBuilder.cs
@@ -145,7 +145,7 @@ namespace WalletWasabi.Tests.NodeBuilding
try
{
var rpc = new RPCClient(credentials, new Uri("http://127.0.0.1:" + rpcPort + "/"), Network.RegTest);
- rpc.Stop();
+ await rpc.StopAsync();
var pidFile = Path.Combine(child, "data", "regtest", pidFileName);
if (File.Exists(pidFile))
@@ -199,7 +199,7 @@ namespace WalletWasabi.Tests.NodeBuilding
{
foreach (CoreNode node in Nodes)
{
- node.Kill();
+ node?.KillAsync().GetAwaiter().GetResult();
}
foreach (IDisposable disposable in Disposables)

MODIFY
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
WalletWasabi.Tests/XunitConfiguration/RegTestFixture.cs
@@ -56,7 +56,7 @@ namespace WalletWasabi.Tests.XunitConfiguration
BackendHost?.StopAsync().GetAwaiter().GetResult();
BackendHost?.Dispose();
- BackendRegTestNode?.Kill(cleanFolder: true);
+ BackendRegTestNode?.KillAsync(cleanFolder: true).GetAwaiter().GetResult();
BackendNodeBuilder?.Dispose();
}
}

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -4,6 +4,7 @@ using NBitcoin.RPC;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Threading.Tasks;
using WalletWasabi.Helpers;
using WalletWasabi.Models;
using WalletWasabi.Models.ChaumianCoinJoin;
@@ -205,9 +206,9 @@ namespace NBitcoin
return Encoders.Base58Check.EncodeData(version.Concat(data).ToArray());
}
- public static void Stop(this RPCClient rpc)
+ public static async Task StopAsync(this RPCClient rpc)
{
- rpc.SendCommand("stop");
+ await rpc.SendCommandAsync("stop");
}
}
}

Use better async practices