Rig.TUnit.Resilience
0.1.0-beta.2
dotnet add package Rig.TUnit.Resilience --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Resilience -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Resilience" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Resilience" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Resilience" />
paket add Rig.TUnit.Resilience --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Resilience, 0.1.0-beta.2"
#:package Rig.TUnit.Resilience@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Resilience&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Resilience&version=0.1.0-beta.2&prerelease
Rig.TUnit.Resilience
Polly 8.x assertions +
FakeTimeProvider-driven deterministic retry/backoff testing:CircuitBreakerAssert,RetryAssert,RateLimitAssert,BulkheadAssert,ChaosInjector.
What this package is
The Rig.TUnit kit for testing Polly-based resilience pipelines. Four
fluent assertion families cover the four Polly strategies
(CircuitBreaker, Retry, RateLimit, Bulkhead), each parameterisable
against a CircuitBreakerStateProvider or equivalent. ResilienceClock
wraps FakeTimeProvider so retries and breaker windows can be
jumped over deterministically — no Thread.Sleep, no flake.
ChaosInjector lets tests flip operations to fail on demand to
exercise breaker / retry paths.
When to use it
- Testing retry + circuit breaker policies end-to-end.
- Verifying rate limits throttle when saturated.
- Asserting bulkhead isolation prevents cascading failures.
- Not for: unit-testing business logic — wrap your service with the real pipeline in an integration test.
Prerequisites
- .NET 10 SDK
Polly8.x +Polly.Extensions(transitive)Microsoft.Extensions.TimeProvider.Testing(transitive)
Quick start
using Polly;
using Polly.CircuitBreaker;
using Rig.TUnit.Resilience;
var state = new CircuitBreakerStateProvider();
var pipeline = new ResiliencePipelineBuilder()
.AddCircuitBreaker(new CircuitBreakerStrategyOptions
{
FailureRatio = 1.0,
MinimumThroughput = 2,
StateProvider = state,
})
.Build();
Options
| Property | Type | Default | Description |
|---|---|---|---|
DefaultBreakDuration |
TimeSpan |
30s |
Applied to breaker strategies |
DefaultSamplingDuration |
TimeSpan |
30s |
Breaker sampling window |
ChaosFailureRate |
double |
0.0 |
ChaosInjector.Execute failure probability |
Fixture + helper APIs
Rig.TUnit.Resilience.CircuitBreakerAssertRig.TUnit.Resilience.RetryAssertRig.TUnit.Resilience.RateLimitAssertRig.TUnit.Resilience.BulkheadAssertRig.TUnit.Resilience.Helpers.ResilienceClockRig.TUnit.Resilience.Helpers.ChaosInjector
Per-test isolation
Each assertion is stateless; state providers + pipelines are per-test.
ResilienceClock owns its own FakeTimeProvider per instance. Safe
under full parallelism.
Parallelism + performance
- Zero containers.
- Per-assertion: microseconds plus the cost of pipeline execution.
- Safe under full parallelism.
Troubleshooting
- Retry backoff does not fire in tests — pipelines default to the
system
TimeProvider; injectResilienceClock.TimeProviderinto theResiliencePipelineBuilder.TimeProviderproperty. CircuitBreakerAssert.After(failures: N)reports wrong state — the breaker'sMinimumThroughputwas not met; tests must fire enough calls to satisfy the sampling threshold.
See docs/troubleshooting.md#resilience.
Provider quirks + edge cases
- Polly 8.x breaking API change —
ResiliencePipeline<T>replacesIAsyncPolicy<T>; assertions assume the new API. - Sampling-window math:
MinimumThroughput+FailureRatiocombine —FailureRatio=1.0, MinimumThroughput=5means 5 consecutive failures in the sampling window trip the breaker. - Bulkhead is provided by
Polly.RateLimitingin v8+ (no more separateBulkheadstrategy).
Benchmarks
See ResilienceBenchmarks.cs;
baseline in benchmarks/baseline-005.json.
Related docs
- Architecture diagram
- Glossary
- Sibling:
Rig.TUnit.Http
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Bogus (>= 35.6.1)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.0.0)
- Polly (>= 8.5.0)
- Polly.Extensions (>= 8.5.0)
- Rig.TUnit.Core (>= 0.1.0-beta.2)
- TUnit.Core (>= 1.34.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rig.TUnit.Resilience:
| Package | Downloads |
|---|---|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 53 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 64 | 4/26/2026 |