Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -5,11 +5,13 @@ using FluentAssertions;
|
||||
using StellaOps.Scheduler.Models;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Scheduler.Queue.Tests;
|
||||
|
||||
public sealed class PlannerAndRunnerMessageTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void PlannerMessage_CanonicalSerialization_RoundTrips()
|
||||
{
|
||||
var schedule = new Schedule(
|
||||
@@ -68,7 +70,8 @@ public sealed class PlannerAndRunnerMessageTests
|
||||
roundTrip.Should().BeEquivalentTo(message, options => options.WithStrictOrdering());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RunnerSegmentMessage_RequiresAtLeastOneDigest()
|
||||
{
|
||||
var act = () => new RunnerSegmentQueueMessage(
|
||||
@@ -80,7 +83,8 @@ public sealed class PlannerAndRunnerMessageTests
|
||||
act.Should().Throw<ArgumentException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RunnerSegmentMessage_CanonicalSerialization_RoundTrips()
|
||||
{
|
||||
var message = new RunnerSegmentQueueMessage(
|
||||
|
||||
@@ -2,30 +2,24 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DotNet.Testcontainers.Builders;
|
||||
using DotNet.Testcontainers.Containers;
|
||||
using DotNet.Testcontainers.Configurations;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StackExchange.Redis;
|
||||
using StellaOps.Scheduler.Models;
|
||||
using StellaOps.Scheduler.Queue.Redis;
|
||||
using Testcontainers.Redis;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Scheduler.Queue.Tests;
|
||||
|
||||
public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
{
|
||||
private readonly RedisTestcontainer _redis;
|
||||
private readonly RedisContainer _redis;
|
||||
private string? _skipReason;
|
||||
|
||||
public RedisSchedulerQueueTests()
|
||||
{
|
||||
var configuration = new RedisTestcontainerConfiguration();
|
||||
|
||||
_redis = new TestcontainersBuilder<RedisTestcontainer>()
|
||||
.WithDatabase(configuration)
|
||||
.Build();
|
||||
_redis = new RedisBuilder().Build();
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
@@ -50,7 +44,8 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
await _redis.DisposeAsync().AsTask();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PlannerQueue_EnqueueLeaseAck_RemovesMessage()
|
||||
{
|
||||
if (SkipIfUnavailable())
|
||||
@@ -86,7 +81,8 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
afterAck.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RunnerQueue_Retry_IncrementsDeliveryAttempt()
|
||||
{
|
||||
if (SkipIfUnavailable())
|
||||
@@ -122,7 +118,8 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
secondLease[0].Attempt.Should().Be(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PlannerQueue_ClaimExpired_ReassignsLease()
|
||||
{
|
||||
if (SkipIfUnavailable())
|
||||
@@ -155,7 +152,8 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
await reclaimed[0].AcknowledgeAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PlannerQueue_RecordsDepthMetrics()
|
||||
{
|
||||
if (SkipIfUnavailable())
|
||||
@@ -190,7 +188,8 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
plannerDepth.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RunnerQueue_DropWhenDeadLetterDisabled()
|
||||
{
|
||||
if (SkipIfUnavailable())
|
||||
@@ -209,6 +208,7 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
TimeProvider.System,
|
||||
async config => (IConnectionMultiplexer)await ConnectionMultiplexer.ConnectAsync(config).ConfigureAwait(false));
|
||||
|
||||
using StellaOps.TestKit;
|
||||
var message = TestData.CreateRunnerMessage();
|
||||
await queue.EnqueueAsync(message);
|
||||
|
||||
@@ -234,7 +234,7 @@ public sealed class RedisSchedulerQueueTests : IAsyncLifetime
|
||||
RetryMaxBackoff = TimeSpan.FromMilliseconds(50),
|
||||
Redis = new SchedulerRedisQueueOptions
|
||||
{
|
||||
ConnectionString = _redis.ConnectionString,
|
||||
ConnectionString = _redis.GetConnectionString(),
|
||||
Database = 0,
|
||||
InitializationTimeout = TimeSpan.FromSeconds(10),
|
||||
Planner = new RedisSchedulerStreamOptions
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace StellaOps.Scheduler.Queue.Tests;
|
||||
|
||||
public sealed class SchedulerQueueServiceCollectionExtensionsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AddSchedulerQueues_RegistersNatsTransport()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
@@ -32,6 +33,7 @@ public sealed class SchedulerQueueServiceCollectionExtensionsTests
|
||||
|
||||
await using var provider = services.BuildServiceProvider();
|
||||
|
||||
using StellaOps.TestKit;
|
||||
var plannerQueue = provider.GetRequiredService<ISchedulerPlannerQueue>();
|
||||
var runnerQueue = provider.GetRequiredService<ISchedulerRunnerQueue>();
|
||||
|
||||
@@ -39,7 +41,8 @@ public sealed class SchedulerQueueServiceCollectionExtensionsTests
|
||||
runnerQueue.Should().BeOfType<NatsSchedulerRunnerQueue>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task SchedulerQueueHealthCheck_ReturnsHealthy_WhenTransportsReachable()
|
||||
{
|
||||
var healthCheck = new SchedulerQueueHealthCheck(
|
||||
@@ -57,7 +60,8 @@ public sealed class SchedulerQueueServiceCollectionExtensionsTests
|
||||
result.Status.Should().Be(HealthStatus.Healthy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task SchedulerQueueHealthCheck_ReturnsUnhealthy_WhenRunnerPingFails()
|
||||
{
|
||||
var healthCheck = new SchedulerQueueHealthCheck(
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="DotNet.Testcontainers" Version="1.7.0-beta.2269" />
|
||||
<PackageReference Include="Testcontainers" Version="4.4.0" />
|
||||
<PackageReference Include="Testcontainers.Redis" Version="4.4.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
|
||||
Reference in New Issue
Block a user