From 6534efae18b77fa4a0905dfc818a3d75fad02851 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 27 Feb 2014 09:03:37 -0800 Subject: [PATCH] Prevent XML error from blowing up integration test --- src/NzbDrone.Test.Common/NzbDroneRunner.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Test.Common/NzbDroneRunner.cs b/src/NzbDrone.Test.Common/NzbDroneRunner.cs index 8622b6555..ab0c82667 100644 --- a/src/NzbDrone.Test.Common/NzbDroneRunner.cs +++ b/src/NzbDrone.Test.Common/NzbDroneRunner.cs @@ -100,18 +100,28 @@ namespace NzbDrone.Test.Common private void SetApiKey() { var configFile = Path.Combine(AppData, "config.xml"); + var attempts = 0; - while (ApiKey == null) + while (ApiKey == null && attempts < 50) { - if (File.Exists(configFile)) + try { - var apiKeyElement = XDocument.Load(configFile) - .XPathSelectElement("Config/ApiKey"); - if (apiKeyElement != null) + if (File.Exists(configFile)) { - ApiKey = apiKeyElement.Value; + var apiKeyElement = XDocument.Load(configFile) + .XPathSelectElement("Config/ApiKey"); + if (apiKeyElement != null) + { + ApiKey = apiKeyElement.Value; + } } } + catch (Exception ex) + { + Console.WriteLine("Error getting API Key from XML file: " + ex.Message, ex); + } + + attempts++; Thread.Sleep(1000); } }