From d76f8e715d59f898a8413ee93b06804bb856d25a Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Sat, 3 Jul 2021 22:37:12 -0500 Subject: [PATCH] Fixed flaky test. (cherry picked from commit f846e0c031d74914d3a02626597df583422164e0) Closes #304 --- .../Client/LogsClient.cs | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Integration.Test/Client/LogsClient.cs b/src/NzbDrone.Integration.Test/Client/LogsClient.cs index 99e4a27ae..e394e780e 100644 --- a/src/NzbDrone.Integration.Test/Client/LogsClient.cs +++ b/src/NzbDrone.Integration.Test/Client/LogsClient.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Threading; using RestSharp; namespace NzbDrone.Integration.Test.Client @@ -12,13 +13,33 @@ namespace NzbDrone.Integration.Test.Client public string[] GetLogFileLines(string filename) { - var request = BuildRequest(filename); - var content = Execute(request, System.Net.HttpStatusCode.OK); + var attempts = 10; + var attempt = 1; + while (true) + { + try + { + var request = BuildRequest(filename); + var content = Execute(request, System.Net.HttpStatusCode.OK); - var lines = content.Split('\n'); - lines = Array.ConvertAll(lines, s => s.TrimEnd('\r')); - Array.Resize(ref lines, lines.Length - 1); - return lines; + var lines = content.Split('\n'); + lines = Array.ConvertAll(lines, s => s.TrimEnd('\r')); + Array.Resize(ref lines, lines.Length - 1); + return lines; + } + catch (Exception ex) + { + if (attempt == attempts) + { + _logger.Error(ex, "Failed to get log lines"); + throw; + } + + _logger.Info(ex, "Failed to get log lines, attempt {0}/{1}", attempt, attempts); + Thread.Sleep(10); + attempt++; + } + } } } }