Files
ThreadPilot/Tests/ThreadPilot.Core.Tests/RetryPolicyServiceTests.cs
T
PrimeBuild-pc c9253f879d Enhance CI/release workflow and app robustness
Add comprehensive CI and release improvements (coverage collection, Codecov upload, SBOM generation), split release workflow into build/smoke-test/release stages with deterministic version resolution, artifact uploads, winget manifest updates and changelog generation. Add a pre-commit hook to block large or unwanted artifacts. Introduce runtime improvements: smoke-test startup mode, improved unhandled/dispatcher/task-exception reporting, ThreadPilotException error codes, single-instance behavior adjustments, and logging enhancements. UI and UX changes include a new Logs tab and LogViewer wiring, DWM title-bar theming helper, navigation serialization/unsaved-changes guard, system-tray update backoff logic, and related viewmodel/service integrations. Also add installer template, helper classes, tests, docs, packaging and build scripts, and minor .gitignore updates.
2026-04-15 22:38:35 +02:00

82 lines
2.4 KiB
C#

/*
* ThreadPilot - retry policy service unit tests.
*/
namespace ThreadPilot.Core.Tests
{
using Microsoft.Extensions.Logging.Abstractions;
using ThreadPilot.Services;
/// <summary>
/// Unit tests for <see cref="RetryPolicyService"/> behavior.
/// </summary>
public sealed class RetryPolicyServiceTests
{
/// <summary>
/// Ensures the retry loop retries transient failures and eventually returns success.
/// </summary>
[Fact]
public async Task ExecuteAsync_RetriesTransientErrors_ThenSucceeds()
{
var service = new RetryPolicyService(NullLogger<RetryPolicyService>.Instance);
var attempts = 0;
var policy = new RetryPolicy
{
MaxAttempts = 3,
InitialDelay = TimeSpan.Zero,
MaxDelay = TimeSpan.Zero,
BackoffMultiplier = 1,
ShouldRetry = _ => true,
};
var result = await service.ExecuteAsync(
async () =>
{
attempts++;
if (attempts < 3)
{
throw new InvalidOperationException("transient");
}
return "ok";
},
policy);
Assert.Equal("ok", result);
Assert.Equal(3, attempts);
}
/// <summary>
/// Ensures non-retriable failures are surfaced immediately.
/// </summary>
[Fact]
public async Task ExecuteAsync_DoesNotRetry_WhenPredicateRejectsException()
{
var service = new RetryPolicyService(NullLogger<RetryPolicyService>.Instance);
var attempts = 0;
var policy = new RetryPolicy
{
MaxAttempts = 5,
InitialDelay = TimeSpan.Zero,
MaxDelay = TimeSpan.Zero,
BackoffMultiplier = 1,
ShouldRetry = _ => false,
};
await Assert.ThrowsAsync<UnauthorizedAccessException>(async () =>
{
await service.ExecuteAsync<string>(
async () =>
{
attempts++;
throw new UnauthorizedAccessException("denied");
},
policy);
});
Assert.Equal(1, attempts);
}
}
}