public async Task LockAsync_WithContention_AcquisitionTimeoutExpires_Throws() { CancellationToken cancellationToken = new CancellationToken(); _mockStorageBlob.Setup(p => p.UploadTextAsync(string.Empty, null, It.Is <AccessCondition>(q => q.IfNoneMatchETag == "*"), null, null, cancellationToken)).Returns(Task.FromResult(true)); int count = 0; _mockStorageBlob.Setup(p => p.AcquireLeaseAsync(_singletonConfig.LockPeriod, null, cancellationToken)) .Callback <TimeSpan?, string, CancellationToken>((mockPeriod, mockLeaseId, mockCancellationToken) => { ++count; }).Returns(() => { return(Task.FromResult <string>(null)); }); SingletonAttribute attribute = new SingletonAttribute(); TimeoutException exception = await Assert.ThrowsAsync <TimeoutException>(async() => await _singletonManager.LockAsync(TestLockId, TestInstanceId, attribute, cancellationToken)); int expectedRetryCount = (int)(_singletonConfig.LockAcquisitionTimeout.TotalMilliseconds / _singletonConfig.LockAcquisitionPollingInterval.TotalMilliseconds); Assert.Equal(expectedRetryCount, count - 1); Assert.Equal("Unable to acquire singleton lock blob lease for blob 'testid' (timeout of 0:00:00.2 exceeded).", exception.Message); _mockStorageBlob.VerifyAll(); }