From 24a67a114459e53c31be0e85eaa2f1a8fad9d754 Mon Sep 17 00:00:00 2001 From: Sohail Hussain Date: Tue, 16 Mar 2021 11:28:34 -0700 Subject: [PATCH] default error handler shouldnt raise exception --- .../HttpProjectConfigManagerTest.cs | 30 ++++++++++++++++++- .../Config/HttpProjectConfigManager.cs | 4 +-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/OptimizelySDK.Tests/ConfigTest/HttpProjectConfigManagerTest.cs b/OptimizelySDK.Tests/ConfigTest/HttpProjectConfigManagerTest.cs index 14454e03..9a3bbb87 100644 --- a/OptimizelySDK.Tests/ConfigTest/HttpProjectConfigManagerTest.cs +++ b/OptimizelySDK.Tests/ConfigTest/HttpProjectConfigManagerTest.cs @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020, Optimizely + * Copyright 2019-2021, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,7 +161,35 @@ public void TestHttpConfigManagerRetreiveProjectConfigByFormat() It.Is(requestMessage => requestMessage.RequestUri.ToString() == "https://cdn.optimizely.com/json/10192104166.json" ))); + Assert.IsNotNull(httpManager.GetConfig()); + + LoggerMock.Verify(_ => _.Log(LogLevel.DEBUG, "Making datafile request to url \"https://cdn.optimizely.com/json/10192104166.json\"")); + httpManager.Dispose(); + } + + [Test] + public void TestHttpProjectConfigManagerDoesntRaiseExceptionForDefaultErrorHandler() + { + var t = MockSendAsync(TestData.Datafile); + + HttpProjectConfigManager httpManager = new HttpProjectConfigManager.Builder() + .WithSdkKey("10192104166") + .WithFormat("https://cdn.optimizely.com/json/{0}.json") + .WithLogger(LoggerMock.Object) + .WithPollingInterval(TimeSpan.FromMilliseconds(1000)) + .WithBlockingTimeoutPeriod(TimeSpan.FromMilliseconds(500)) + .WithStartByDefault() + .Build(true); + + t.Wait(1000); + HttpClientMock.Verify(_ => _.SendAsync( + It.Is(requestMessage => + requestMessage.RequestUri.ToString() == "https://cdn.optimizely.com/json/10192104166.json" + ))); + var datafileConfig = httpManager.GetConfig(); + Assert.IsNotNull(datafileConfig); + Assert.IsNull(datafileConfig.GetExperimentFromKey("project_config_not_valid").Key); LoggerMock.Verify(_ => _.Log(LogLevel.DEBUG, "Making datafile request to url \"https://cdn.optimizely.com/json/10192104166.json\"")); httpManager.Dispose(); } diff --git a/OptimizelySDK/Config/HttpProjectConfigManager.cs b/OptimizelySDK/Config/HttpProjectConfigManager.cs index b886f894..8b909755 100644 --- a/OptimizelySDK/Config/HttpProjectConfigManager.cs +++ b/OptimizelySDK/Config/HttpProjectConfigManager.cs @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020, Optimizely + * Copyright 2019-2021, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -301,7 +301,7 @@ public HttpProjectConfigManager Build(bool defer) Logger = new DefaultLogger(); if (ErrorHandler == null) - ErrorHandler = new DefaultErrorHandler(); + ErrorHandler = new DefaultErrorHandler(Logger, false); if (string.IsNullOrEmpty(Format)) {