test(notifications): update outbox fixtures with tracked entities
Heimdall Gitea / Detect CI scope (pull_request) Successful in 4s
Heimdall Gitea / Build and tests (pull_request) Failing after 4m18s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 1s
Heimdall Gitea / Detect CI scope (pull_request) Successful in 4s
Heimdall Gitea / Build and tests (pull_request) Failing after 4m18s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 1s
This commit is contained in:
1 parent
1371eefb70
commit
8fa43ac1b6
1 file changed
+30
-23
@@ -10,7 +10,6 @@ using Heimdall.Infrastructure.Services;
|
||||
using Heimdall.IntegrationTests.Controllers;
|
||||
using Heimdall.IntegrationTests.Factories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using NSubstitute;
|
||||
@@ -66,12 +65,14 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p
|
||||
{
|
||||
var (_, futureId) = await CreateDeliveryAsync(NotificationChannel.Email, "future@example.test", "Future");
|
||||
var (_, leasedId) = await CreateDeliveryAsync(NotificationChannel.Email, "leased@example.test", "Leased");
|
||||
await UpdateDeliveryAsync(futureId, update => update
|
||||
.SetProperty(d => d.NextAttemptAt, (DateTime?)DateTime.UtcNow.AddMinutes(10)));
|
||||
await UpdateDeliveryAsync(leasedId, update => update
|
||||
.SetProperty(d => d.Status, NotificationDeliveryStatus.Processing)
|
||||
.SetProperty(d => d.Attempts, 1)
|
||||
.SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(5)));
|
||||
await UpdateDeliveryAsync(futureId, delivery =>
|
||||
delivery.NextAttemptAt = DateTime.UtcNow.AddMinutes(10));
|
||||
await UpdateDeliveryAsync(leasedId, delivery =>
|
||||
{
|
||||
delivery.Status = NotificationDeliveryStatus.Processing;
|
||||
delivery.Attempts = 1;
|
||||
delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(5);
|
||||
});
|
||||
var email = new RecordingEmailService();
|
||||
|
||||
await ProcessDeliveryAsync(futureId, email: email);
|
||||
@@ -90,10 +91,12 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p
|
||||
public async Task ProcessAsync_ExpiredLease_ReclaimsAndCompletesDelivery()
|
||||
{
|
||||
var (_, deliveryId) = await CreateDeliveryAsync(NotificationChannel.Email, "retry@example.test", "Retry");
|
||||
await UpdateDeliveryAsync(deliveryId, update => update
|
||||
.SetProperty(d => d.Status, NotificationDeliveryStatus.Processing)
|
||||
.SetProperty(d => d.Attempts, 1)
|
||||
.SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(-1)));
|
||||
await UpdateDeliveryAsync(deliveryId, delivery =>
|
||||
{
|
||||
delivery.Status = NotificationDeliveryStatus.Processing;
|
||||
delivery.Attempts = 1;
|
||||
delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(-1);
|
||||
});
|
||||
var email = new RecordingEmailService();
|
||||
|
||||
await ProcessDeliveryAsync(deliveryId, email: email);
|
||||
@@ -113,14 +116,18 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p
|
||||
var (_, futureId) = await CreateDeliveryAsync(NotificationChannel.Email, "future@example.test", "Future");
|
||||
var (_, activeLeaseId) = await CreateDeliveryAsync(NotificationChannel.Ntfy, "active-topic", "Active");
|
||||
var (_, expiredLeaseId) = await CreateDeliveryAsync(NotificationChannel.Email, "expired@example.test", "Expired");
|
||||
await UpdateDeliveryAsync(futureId, update => update
|
||||
.SetProperty(d => d.NextAttemptAt, (DateTime?)DateTime.UtcNow.AddMinutes(10)));
|
||||
await UpdateDeliveryAsync(activeLeaseId, update => update
|
||||
.SetProperty(d => d.Status, NotificationDeliveryStatus.Processing)
|
||||
.SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(5)));
|
||||
await UpdateDeliveryAsync(expiredLeaseId, update => update
|
||||
.SetProperty(d => d.Status, NotificationDeliveryStatus.Processing)
|
||||
.SetProperty(d => d.LeaseExpiresAt, (DateTime?)DateTime.UtcNow.AddMinutes(-1)));
|
||||
await UpdateDeliveryAsync(futureId, delivery =>
|
||||
delivery.NextAttemptAt = DateTime.UtcNow.AddMinutes(10));
|
||||
await UpdateDeliveryAsync(activeLeaseId, delivery =>
|
||||
{
|
||||
delivery.Status = NotificationDeliveryStatus.Processing;
|
||||
delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(5);
|
||||
});
|
||||
await UpdateDeliveryAsync(expiredLeaseId, delivery =>
|
||||
{
|
||||
delivery.Status = NotificationDeliveryStatus.Processing;
|
||||
delivery.LeaseExpiresAt = DateTime.UtcNow.AddMinutes(-1);
|
||||
});
|
||||
|
||||
var backgroundJobs = Substitute.For<IBackgroundJobClient>();
|
||||
backgroundJobs.Create(Arg.Any<Job>(), Arg.Any<IState>()).Returns("job-id");
|
||||
@@ -158,13 +165,13 @@ public sealed class NotificationDeliveryOutboxTests(PostgreSqlContainerFixture p
|
||||
return (notification.Id, delivery.Id);
|
||||
}
|
||||
|
||||
private async Task UpdateDeliveryAsync(Guid deliveryId,
|
||||
System.Linq.Expressions.Expression<Func<SetPropertyCalls<NotificationDelivery>,
|
||||
SetPropertyCalls<NotificationDelivery>>> update)
|
||||
private async Task UpdateDeliveryAsync(Guid deliveryId, Action<NotificationDelivery> update)
|
||||
{
|
||||
await using var scope = Factory.Services.CreateAsyncScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await db.NotificationDeliveries.Where(d => d.Id == deliveryId).ExecuteUpdateAsync(update);
|
||||
var delivery = await db.NotificationDeliveries.SingleAsync(d => d.Id == deliveryId);
|
||||
update(delivery);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private async Task ProcessDeliveryAsync(Guid deliveryId,
|
||||
|
||||
Reference in new issue
Block a user