elsa-core/test/unit/Elsa.Mediator.UnitTests
Avinesh Singh ac623118a4
Propagate exceptions from command handlers correctly (#7218)
* Propagate exceptions from command handlers correctly

This is to make `CommandHandlerInvokerMiddleware` correctly 'await' the task before accessing its result, similar to how this is done in `RequestHandlerInvokerMiddleware`. Without this change, attempting to access result of a cancelled task would result in TargetInvocationException / AggregateException which breaks the task processing in `BackgroundCommandSenderHostedService` due to unhandled exception, thus breaking the background queue and particularly in bulk dispatch workflow causing remaining workflows to not get dispatched

* Address review comments

Use ExceptionDispatchInfo to prevent misleading stacktrace. As well use disposable fixture to actually dispose CommandSender,

* Address review comments

- Refactor duplicated unwrapping logic into shared InvokeAndUnwrap helper method
- Simplify CommandHandlerInvokerMiddleware to be consistent with
  RequestHandlerInvokerMiddleware (remove redundant await)
- Add Threshold property to test project for consistency

* add ConfigureAwait(false) consistently to middlewares

- Add ConfigureAwait(false) to await statements in both CommandHandlerInvokerMiddleware and RequestHandlerInvokerMiddleware for consistency and to follow library code best practices
- Increase test timeout from 50ms to 100ms for better CI reliability while still maintaining adequate margin (handler has 500ms delay)
2026-02-09 10:58:49 +01:00
..
CommandCancellationBehaviorTests.cs Propagate exceptions from command handlers correctly (#7218) 2026-02-09 10:58:49 +01:00
Elsa.Mediator.UnitTests.csproj Propagate exceptions from command handlers correctly (#7218) 2026-02-09 10:58:49 +01:00