Skip to content

Commit

Permalink
[FSSDK-9526] refact: Implements a warning log for polling interval le…
Browse files Browse the repository at this point in the history
…ss than 30s (#365)

* Added warn log if the interval is set to less than 30

---------

Co-authored-by: NomanShoaib <m.nomanshoaib09@gmail.com>
Co-authored-by: Mike Chu <104384559+mikechu-optimizely@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 3, 2023
1 parent 8c7847f commit f3a21d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions OptimizelySDK.Tests/ConfigTest/PollingProjectConfigManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ public void TestTimedoutOnlyIfSchedulerStarted()
configManager.Dispose();
}

[Test]
public void TestWarnLogIfPollingTimeIsLessThanThirty()
{
var below30Seconds = TimeSpan.FromSeconds(29);
_ = new TestPollingProjectConfigManager(below30Seconds,
TimeSpan.FromSeconds(10), true, LoggerMock.Object, new int[] { });
LoggerMock.Verify(l => l.Log(LogLevel.WARN,
"Polling intervals below 30 seconds are not recommended."), Times.Once);
}
[Test]
public void TestWarnLogNotTriggeredIfPollingTimeIsGreaterThanThirty()
{
var above30Seconds = TimeSpan.FromMinutes(1);
_ = new TestPollingProjectConfigManager(above30Seconds,
TimeSpan.FromMilliseconds(10), true, LoggerMock.Object, new int[] { });
LoggerMock.Verify(l => l.Log(LogLevel.WARN,
"Polling intervals below 30 seconds are not recommended."), Times.Never);
}

[Test]
public void TestDontTimedoutIfSchedulerNotStarted()
{
Expand Down
4 changes: 4 additions & 0 deletions OptimizelySDK/Config/PollingProjectConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public PollingProjectConfigManager(TimeSpan period, TimeSpan blockingTimeout,
Logger = logger;
ErrorHandler = errorHandler;
BlockingTimeout = blockingTimeout;
if (period.TotalSeconds < 30)
{
Logger?.Log(LogLevel.WARN, "Polling intervals below 30 seconds are not recommended.");
}
PollingInterval = period;
AutoUpdate = autoUpdate;

Expand Down

0 comments on commit f3a21d5

Please sign in to comment.