Skip to content

Commit

Permalink
Fix Azure#2363 - make lease timeout range check more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbatum committed Mar 29, 2018
1 parent 928d2f6 commit 043561c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/WebJobs.Script/Host/PrimaryHostCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public static PrimaryHostCoordinator Create(
ILoggerFactory loggerFactory,
TimeSpan? renewalInterval = null)
{
if (leaseTimeout.TotalSeconds < 15 || leaseTimeout.TotalSeconds > 60)
if (leaseTimeout < TimeSpan.FromSeconds(15) || leaseTimeout > TimeSpan.FromSeconds(60))
{
throw new ArgumentOutOfRangeException(nameof(leaseTimeout), $"The {nameof(leaseTimeout)} should be between 15 and 60 seconds");
throw new ArgumentOutOfRangeException(nameof(leaseTimeout), $"The {nameof(leaseTimeout)} should be between 15 and 60 seconds but was '{leaseTimeout}'");
}

var manager = new PrimaryHostCoordinator(lockManager, leaseTimeout, hostId, instanceId, loggerFactory, renewalInterval);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ private static IDistributedLockManager CreateLockManager()
return lockManager;
}

[Theory]
[InlineData(14.99)]
[InlineData(60.01)]
public void RejectsInvalidLeaseTimeout(double leaseTimeoutSeconds)
{
var leaseTimeout = TimeSpan.FromSeconds(leaseTimeoutSeconds);

string hostId = Guid.NewGuid().ToString();
string instanceId = Guid.NewGuid().ToString();

Assert.Throws<ArgumentOutOfRangeException>(
() => PrimaryHostCoordinator.Create(CreateLockManager(), leaseTimeout, hostId, instanceId, _loggerFactory));
}

[Fact]
public async Task HasLease_WhenLeaseIsAcquired_ReturnsTrue()
{
Expand Down

0 comments on commit 043561c

Please sign in to comment.