[Fix] Address xUnit1031 warnings#3992
Conversation
xUnit1031: Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead.
| { | ||
| // arrange | ||
| _message.Header.Subject = "test subject"; | ||
| _messageProducer.Send(_message); |
There was a problem hiding this comment.
Reactor tests are to test sync code.
Please revert this line
| public void When_throwing_defer_action_respect_redrive_async() | ||
| public async Task When_throwing_defer_action_respect_redrive_async() | ||
| { | ||
| _sender.Send(_message); |
There was a problem hiding this comment.
Reactor tests are to test sync code.
Please revert this line
iancooper
left a comment
There was a problem hiding this comment.
PR Review: fix xUnit1031
Summary
This PR addresses the xUnit1031 analyzer warning: "Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead."
Changes Overview
All 6 files follow the same pattern - converting sync test methods to async and replacing blocking calls:
| File | Changes |
|---|---|
| AWS FIFO Reactor tests (3 files) | void → async Task, .GetAwaiter().GetResult() → await, Send() → SendAsync() |
| Kafka Reactor test | void → async Task, .GetAwaiter().GetResult() → await |
| RMQ Proactor test | void → async Task, .CreateAsync().GetAwaiter().GetResult() → await .CreateAsync() |
| RMQ Reactor test | void → async Task, .Wait() → await |
Specific Transformations
// Before (blocking - can cause deadlocks)
Task.Delay(1000).GetAwaiter().GetResult();
Task.Delay(500).Wait();
Task.WaitAll(task);
// After (properly async)
await Task.Delay(1000);
await Task.Delay(500);
await task;Observations
- Consistent fix pattern - All blocking operations properly converted to await
- When_throwing_defer_action_respect_redrive.cs - Nicely handles the
Task.Factory.StartNew()pattern by awaiting the task at the end instead of usingTask.WaitAll() - Mixed sync/async producer calls - Some tests now use
SendAsync()(AWS tests) while others keepSend()(RMQ Reactor test). This appears intentional - the RMQ Reactor test seems to be testing the synchronous producer path specifically
Verdict
Clean fix that addresses a legitimate analyzer warning and removes potential deadlock scenarios. The changes are minimal and focused.
🤖 Generated with Claude Code
There was a problem hiding this comment.
No application code in the PR — skipped Code Health checks.
See analysis details in CodeScene
Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.
|
Closed with no activity |
xUnit1031: Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead.