Skip to content

Commit b1120ce

Browse files
Fix TestDistributedLockProvider registration to properly decorate IDistributedLockProvider (#7166)
* Initial plan * Fix TestDistributedLockProvider registration to use Decorate pattern and fix variable reference bug Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> * Add runtime check for TestDistributedLockProvider registration Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sfmskywalker <938393+sfmskywalker@users.noreply.github.com>
1 parent 50b2ae6 commit b1120ce

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/modules/Elsa.Workflows.Runtime.Distributed/Services/DistributedWorkflowClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private static ResiliencePipeline CreateRetryPipeline(
146146
Delay = TimeSpan.FromMilliseconds(500),
147147
BackoffType = DelayBackoffType.Exponential,
148148
UseJitter = true,
149-
ShouldHandle = new PredicateBuilder().Handle<Exception>(ex => transientExceptionDetectionService.IsTransient(ex)),
149+
ShouldHandle = new PredicateBuilder().Handle<Exception>(transientExceptionDetector.IsTransient),
150150
OnRetry = args =>
151151
{
152152
logger.LogWarning(args.Outcome.Exception, "Transient error acquiring lock for workflow instance {WorkflowInstanceId}. Attempt {AttemptNumber} of {MaxAttempts}.", workflowInstanceId, args.AttemptNumber + 1, maxRetryAttempts);

test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/WorkflowServer.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,17 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
129129

130130
builder.ConfigureTestServices(services =>
131131
{
132-
services.AddSingleton<TestDistributedLockProvider>();
132+
// Decorate IDistributedLockProvider with TestDistributedLockProvider so tests use it
133+
services.Decorate<IDistributedLockProvider, TestDistributedLockProvider>();
134+
135+
// Also register TestDistributedLockProvider as itself so tests can access it directly for configuration
136+
services.AddSingleton(sp =>
137+
{
138+
var provider = sp.GetRequiredService<IDistributedLockProvider>();
139+
if (provider is not TestDistributedLockProvider testProvider)
140+
throw new InvalidOperationException($"Expected IDistributedLockProvider to be decorated with TestDistributedLockProvider, but got {provider.GetType().Name}");
141+
return testProvider;
142+
});
133143

134144
services
135145
.AddSingleton<SignalManager>()

0 commit comments

Comments
 (0)