apply a few best practices
MODIFY
MagicalCryptoWallet.Tests/NodeBuilding/CoreNode.cs
MagicalCryptoWallet.Tests/NodeBuilding/CoreNode.cs
@@ -10,7 +10,6 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -60,7 +59,7 @@ namespace MagicalCryptoWallet.Tests.NodeBuilding
_Builder = builder;
_folder = folder;
_state = CoreNodeState.Stopped;
- CleanFolder();
+ CleanFolder().Wait();
Directory.CreateDirectory(folder);
DataDir = Path.Combine(folder, "data");
Directory.CreateDirectory(DataDir);
@@ -72,15 +71,15 @@ namespace MagicalCryptoWallet.Tests.NodeBuilding
FindPorts(_ports);
}
- private void CleanFolder()
+ private async Task CleanFolder()
{
try
{
- IoHelpers.DeleteRecursivelyWithMagicDust(_folder);
+ await IoHelpers.DeleteRecursivelyWithMagicDustAsync(_folder);
}
catch (DirectoryNotFoundException) { }
}
-#if !NOSOCKET
+
public void Sync(CoreNode node, bool keepConnection = false)
{
var rpc = CreateRPCClient();
@@ -93,7 +92,7 @@ namespace MagicalCryptoWallet.Tests.NodeBuilding
if (!keepConnection)
rpc.RemoveNode(node.Endpoint);
}
-#endif
+
private CoreNodeState _state;
public CoreNodeState State
{
@@ -112,10 +111,6 @@ namespace MagicalCryptoWallet.Tests.NodeBuilding
return _ports[0];
}
}
- public void Start()
- {
- StartAsync().GetAwaiter().GetResult();
- }
private readonly NetworkCredential Creds;
public RPCClient CreateRPCClient()
@@ -296,7 +291,7 @@ namespace MagicalCryptoWallet.Tests.NodeBuilding
}
_state = CoreNodeState.Killed;
if (cleanFolder)
- CleanFolder();
+ CleanFolder().Wait();
}
}

MODIFY
MagicalCryptoWallet.Tests/P2pTests.cs
MagicalCryptoWallet.Tests/P2pTests.cs
@@ -190,10 +190,10 @@ namespace MagicalCryptoWallet.Tests
[Fact]
public async Task FilterBuilderTestAsync()
{
- using (var builder = NodeBuilder.Create())
+ using (var builder = await NodeBuilder.CreateAsync())
{
- builder.CreateNode();
- builder.StartAll();
+ await builder.CreateNodeAsync();
+ await builder.StartAllAsync();
CoreNode regtestNode = builder.Nodes[0];
regtestNode.Generate(101);
RPCClient rpc = regtestNode.CreateRPCClient();

MODIFY
MagicalCryptoWallet.Tests/RegTests.cs
MagicalCryptoWallet.Tests/RegTests.cs
@@ -35,9 +35,9 @@ namespace MagicalCryptoWallet.Tests
if (Fixture.BackendNodeBuilder == null)
{
- Fixture.BackendNodeBuilder = NodeBuilder.Create();
- Fixture.BackendNodeBuilder.CreateNode();
- Fixture.BackendNodeBuilder.StartAll();
+ Fixture.BackendNodeBuilder = NodeBuilder.CreateAsync().Result;
+ Fixture.BackendNodeBuilder.CreateNodeAsync().Wait();
+ Fixture.BackendNodeBuilder.StartAllAsync().Wait();
Fixture.BackendRegTestNode = Fixture.BackendNodeBuilder.Nodes[0];
Fixture.BackendRegTestNode.Generate(101);
var rpc = Fixture.BackendRegTestNode.CreateRPCClient();
@@ -50,16 +50,17 @@ namespace MagicalCryptoWallet.Tests
.UseStartup<Startup>()
.UseUrls(Fixture.BackendEndPoint)
.Build();
- Fixture.BackendHost.RunAsync();
+ var hostInitializationTask = Fixture.BackendHost.RunAsync();
Logger.LogInfo<SharedFixture>($"Started Backend webhost: {Fixture.BackendEndPoint}");
- Task.Delay(3000).GetAwaiter().GetResult(); // Wait for server to initialize (Without this OSX CI will fail)
+ var delayTask = Task.Delay(3000);
+ Task.WaitAny(delayTask, hostInitializationTask); // Wait for server to initialize (Without this OSX CI will fail)
}
}
private async Task AssertFiltersInitializedAsync()
{
- var firstHash = Global.RpcClient.GetBlockHash(0);
+ var firstHash = await Global.RpcClient.GetBlockHashAsync(0);
while (true)
{
using (var client = new TorHttpClient(new Uri(Fixture.BackendEndPoint)))

MODIFY
MagicalCryptoWallet/Helpers/IoHelpers.cs
MagicalCryptoWallet/Helpers/IoHelpers.cs
@@ -10,7 +10,7 @@ namespace System.IO
public static class IoHelpers
{
// http://stackoverflow.com/a/14933880/2061103
- public static void DeleteRecursivelyWithMagicDust(string destinationDir)
+ public static async Task DeleteRecursivelyWithMagicDustAsync(string destinationDir)
{
const int magicDust = 10;
for (var gnomes = 1; gnomes <= magicDust; gnomes++)
@@ -31,7 +31,7 @@ namespace System.IO
Logger.LogDebug($"Gnomes prevent deletion of {destinationDir}! Applying magic dust, attempt #{gnomes}.", nameof(IoHelpers));
// see http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true for more magic
- Thread.Sleep(100);
+ await Task.Delay(100);
continue;
}
catch (UnauthorizedAccessException)
@@ -42,7 +42,7 @@ namespace System.IO
Logger.LogDebug($"Gnomes prevent deletion of {destinationDir}! Applying magic dust, attempt #{gnomes}.", nameof(IoHelpers));
// see http://stackoverflow.com/questions/329355/cannot-delete-directory-with-directory-deletepath-true for more magic
- Thread.Sleep(100);
+ await Task.Delay(100);
continue;
}
return;

apply a few best practices