Skip to content

[Fix] Address xUnit1031 warnings#3992

Closed
SimonCropp wants to merge 3 commits into
BrighterCommand:masterfrom
SimonCropp:fix-xUnit1031
Closed

[Fix] Address xUnit1031 warnings#3992
SimonCropp wants to merge 3 commits into
BrighterCommand:masterfrom
SimonCropp:fix-xUnit1031

Conversation

@SimonCropp

Copy link
Copy Markdown
Contributor

xUnit1031: Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead.

xUnit1031: Test methods should not use blocking task operations, as they can cause deadlocks. Use an async test method and await instead.
codescene-delta-analysis[bot]

This comment was marked as outdated.

{
// arrange
_message.Header.Subject = "test subject";
_messageProducer.Send(_message);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reactor tests are to test sync code.

Please revert this line

codescene-delta-analysis[bot]

This comment was marked as outdated.

@iancooper iancooper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) voidasync Task, .GetAwaiter().GetResult()await, Send()SendAsync()
Kafka Reactor test voidasync Task, .GetAwaiter().GetResult()await
RMQ Proactor test voidasync Task, .CreateAsync().GetAwaiter().GetResult()await .CreateAsync()
RMQ Reactor test voidasync 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

  1. Consistent fix pattern - All blocking operations properly converted to await
  2. When_throwing_defer_action_respect_redrive.cs - Nicely handles the Task.Factory.StartNew() pattern by awaiting the task at the end instead of using Task.WaitAll()
  3. Mixed sync/async producer calls - Some tests now use SendAsync() (AWS tests) while others keep Send() (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

@iancooper iancooper added 2 - In Progress .NET Pull requests that update .net code labels Jan 27, 2026

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iancooper iancooper changed the title fix xUnit1031 [Fix] Address xUnit1031 warnings Jan 28, 2026
@holytshirt holytshirt added the Bug label Apr 4, 2026
@iancooper

Copy link
Copy Markdown
Member

Closed with no activity

@iancooper iancooper closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 - In Progress Bug .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants