Skip to content

Commit

Permalink
Merge branch 'hotfix/#22-bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
baynezy committed Nov 8, 2016
2 parents e60000a + 324c248 commit 23bb61c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
32 changes: 32 additions & 0 deletions SiteWarmer/SiteWarmer.Core.Test/RepeatWarmerTest.cs
Expand Up @@ -54,6 +54,38 @@ public void Warm_WhenInitialCallFails_ThenRetryOnlyTheNumberOfTimesWeAreConfigur
Assert.AreNotEqual(Check.Ok, results[0].Status);
}

[Test]
public void Warm_WhenCallPasses_ThenDoNotRetryUrl()
{
var config = new Mock<IConfig>();
config.Setup(m => m.Checks).Returns(new List<Check>
{
new Check
{
Url = "http://www.google.com"
},
new Check
{
Url = "http://www.google.co.uk"
}
});

var requester = new Mock<IRequester>();
requester.Setup(m => m.Check(It.IsAny<Check>()))
.Callback((Check c) =>
{
c.Status = c.Url.Equals("http://www.google.com") ? 500 : Check.Ok;
});

var logger = BaseLogger();

var warmer = new RepeatWarmer(config.Object, requester.Object, logger.Object, 2);

warmer.Warm();

requester.Verify(f => f.Check(It.IsAny<Check>()), Times.Exactly(3));
}

private static Mock<IConfig> BaseConfig()
{
var config = new Mock<IConfig>();
Expand Down
21 changes: 16 additions & 5 deletions SiteWarmer/SiteWarmer.Core/CustomWarmer.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SiteWarmer.Core.Comms;
using SiteWarmer.Core.Config;
Expand Down Expand Up @@ -30,11 +31,21 @@ public CustomWarmer(IConfig config, IRequester requester)
/// <param name="action">Custom action to execute after each Check is requested</param>
public void Warm(Action<Check> action)
{
Parallel.ForEach(_config.Checks, check =>
{
_requester.Check(check);
action.Invoke(check);
});
Warm(_config.Checks, action);
}

/// <summary>
/// Warm all URLs in the Check collection passed in
/// </summary>
/// <param name="checks">Check collection to warm</param>
/// <param name="action">Custom action to execute after each Check is requested</param>
public void Warm(IList<Check> checks, Action<Check> action)
{
Parallel.ForEach(checks, check =>
{
_requester.Check(check);
action.Invoke(check);
});
}
}
}
2 changes: 1 addition & 1 deletion SiteWarmer/SiteWarmer.Core/Warmer.cs
Expand Up @@ -49,7 +49,7 @@ public IList<Check> Warm()
/// <returns>Whether all checks have completed</returns>
protected virtual bool RunChecks(IList<Check> checks)
{
_warmer.Warm(_logger.Log);
_warmer.Warm(checks, _logger.Log);

return true;
}
Expand Down

0 comments on commit 23bb61c

Please sign in to comment.