From 288dc9b62639cd88c95f16caccd4aa5c56767706 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 20 Aug 2019 16:10:44 +0900 Subject: [PATCH] Do not loop infinitely waiting for btcpay to start --- BTCPayServer.Tests/BTCPayServerTester.cs | 30 ++++++++++++++---------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/BTCPayServer.Tests/BTCPayServerTester.cs b/BTCPayServer.Tests/BTCPayServerTester.cs index 5c7a15971..7b58b8fbc 100644 --- a/BTCPayServer.Tests/BTCPayServerTester.cs +++ b/BTCPayServer.Tests/BTCPayServerTester.cs @@ -228,26 +228,32 @@ namespace BTCPayServer.Tests private async Task WaitSiteIsOperational() { - var synching = WaitIsFullySynched(); - var accessingHomepage = WaitCanAccessHomepage(); - await Task.WhenAll(synching, accessingHomepage).ConfigureAwait(false); - } - - private async Task WaitCanAccessHomepage() - { - var resp = await HttpClient.GetAsync("/").ConfigureAwait(false); - while (resp.StatusCode != HttpStatusCode.OK) + using (var cts = new CancellationTokenSource(10_000)) { - await Task.Delay(10).ConfigureAwait(false); + var synching = WaitIsFullySynched(cts.Token); + var accessingHomepage = WaitCanAccessHomepage(cts.Token); + await Task.WhenAll(synching, accessingHomepage).ConfigureAwait(false); } } - private async Task WaitIsFullySynched() + private async Task WaitCanAccessHomepage(CancellationToken cancellationToken) + { + while (true) + { + var resp = await HttpClient.GetAsync("/", cancellationToken).ConfigureAwait(false); + if (resp.StatusCode != HttpStatusCode.OK) + await Task.Delay(10, cancellationToken).ConfigureAwait(false); + else + break; + } + } + + private async Task WaitIsFullySynched(CancellationToken cancellationToken) { var dashBoard = GetService(); while (!dashBoard.IsFullySynched()) { - await Task.Delay(10).ConfigureAwait(false); + await Task.Delay(10, cancellationToken).ConfigureAwait(false); } }