Fix unreliable tests

This commit is contained in:
nicolas.dorier 2018-10-28 22:46:03 +09:00
parent 8e8669d63f
commit 8be4256278
4 changed files with 8 additions and 21 deletions

View File

@ -256,18 +256,5 @@ namespace BTCPayServer.Tests
if (_Host != null)
_Host.Dispose();
}
public void WaitFullNodeAvailable(string cryptoCode)
{
using (var cts = new CancellationTokenSource(5000))
{
var dashboard = GetService<NBXplorerDashboard>();
while (!dashboard.IsFullySynched(cryptoCode, out var unused))
{
Thread.Sleep(10);
cts.Token.ThrowIfCancellationRequested();
}
}
}
}
}

View File

@ -84,7 +84,7 @@ namespace BTCPayServer.Tests
/// Connect a customer LN node to the merchant LN node
/// </summary>
/// <returns></returns>
public Task EnsureConnectedToDestinations()
public Task EnsureChannelsSetup()
{
return BTCPayServer.Lightning.Tests.ConnectChannels.ConnectAll(ExplorerNode, GetLightningSenderClients(), GetLightningDestClients());
}

View File

@ -399,18 +399,18 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Unreliable", "Unreliable")]
public void CanSetLightningServer()
public async Task CanSetLightningServer()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
var storeController = user.GetController<StoresController>();
Assert.IsType<ViewResult>(storeController.UpdateStore());
Assert.IsType<ViewResult>(storeController.AddLightningNode(user.StoreId, "BTC"));
tester.PayTester.WaitFullNodeAvailable("BTC");
var testResult = storeController.AddLightningNode(user.StoreId, new LightningNodeViewModel()
{
ConnectionString = "type=charge;server=" + tester.MerchantCharge.Client.Uri.AbsoluteUri,
@ -464,13 +464,12 @@ namespace BTCPayServer.Tests
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterLightningNode("BTC", type);
user.RegisterDerivationScheme("BTC");
await tester.EnsureConnectedToDestinations();
await CanSendLightningPaymentCore(tester, user);
await Task.WhenAll(Enumerable.Range(0, 5)
@ -1356,11 +1355,12 @@ namespace BTCPayServer.Tests
[Fact]
[Trait("Unreliable", "Unreliable")]
public void CanSetPaymentMethodLimits()
public async Task CanSetPaymentMethodLimits()
{
using (var tester = ServerTester.Create())
{
tester.Start();
await tester.EnsureChannelsSetup();
var user = tester.NewAccount();
user.GrantAccess();
user.RegisterDerivationScheme("BTC");

View File

@ -90,10 +90,10 @@ namespace BTCPayServer.Payments.Lightning
throw new PaymentMethodUnavailableException($"No lightning node public address has been configured");
}
var blocksGap = Math.Abs(info.BlockHeight - summary.Status.ChainHeight);
var blocksGap = summary.Status.ChainHeight - info.BlockHeight;
if (blocksGap > 10)
{
throw new PaymentMethodUnavailableException($"The lightning is not synched ({blocksGap} blocks)");
throw new PaymentMethodUnavailableException($"The lightning node is not synched ({blocksGap} blocks left)");
}
return info.NodeInfo;