Files
Heimdall/tests/Heimdall.Api.Tests/RecurringJobStartupRetryTests.cs
T
arnaud.dartois 6381bbd0b5
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Successful in 20m51s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m34s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 9m53s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Successful in 27m0s
Heimdall Gitea / CI policy (pull_request) Successful in 5s
fix(web): retry Hangfire startup lock contention
2026-11-07 09:25:12 +01:00

33 lines
999 B
C#

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");
}
}