Files
Heimdall/tests/Heimdall.Api.Tests/RecurringJobStartupRetryTests.cs
T

32 lines
999 B
C#
Raw Normal View History

using Hangfire;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NSubstitute;
using Shouldly;
namespace Heimdall.Api.Tests;
public sealed class RecurringJobStartupRetryTests
{
[Fact]
public async Task ConfigureRecurringJobs_RetriesDistributedLockContention()
{
var manager = Substitute.For<IRecurringJobManager>();
var calls = 0;
manager.When(x => x.RemoveIfExists(Arg.Any<string>())).Do(_ =>
{
if (Interlocked.Increment(ref calls) == 1)
throw new Hangfire.PostgreSql.PostgreSqlDistributedLockException("synthetic lock contention");
});
using var services = new ServiceCollection()
.AddLogging()
.AddSingleton(manager)
.BuildServiceProvider();
await Program.ConfigureRecurringJobsAsync(services, CancellationToken.None);
calls.ShouldBe(2);
manager.Received(2).RemoveIfExists("heartbeat-monitor");
}
}