test: convert BroadcastToPlayersInRange tests to async/await (xUnit1031) #668

Closed
opened 2026-07-17 17:01:36 +00:00 by spikerj · 2 comments
Owner

The 18 BroadcastToPlayersInRange_* tests in BroadcastToPlayersInRangeTests.cs set up state via _zone.AddPlayerAsync(...).Wait() inside synchronous public void methods. SonarQube xUnit1031 flags blocking task operations in test methods.

Analysis: xUnit runs tests without a SynchronizationContext, so the classic .Wait()/.Result deadlock cannot occur here — the rules headline danger does not apply. But the fix is still a genuine, low-risk improvement: async Task + await is the idiomatic async-test pattern and surfaces assertion/exception failures directly instead of wrapping them in AggregateException. So this is a real (if minor) cleanup, not a false positive.

Change: method-aware conversion — only the 18 tests that actually block were converted to async Task with await; the one test with no async setup stays void (avoids a CS1998 async-without-await). Added using System.Threading.Tasks;.

Scope: one test file. Build clean (0 errors, no CS1998); all 34 test cases pass unchanged. Clears 27 of the 47 open xUnit1031 findings. SonarQube rule external_roslyn:xUnit1031.

Follow-up: remaining xUnit1031 live in BaseZoneTests (mixed sync/async) and a few others — deferred to keep this PR contained and verifiable.

The 18 `BroadcastToPlayersInRange_*` tests in `BroadcastToPlayersInRangeTests.cs` set up state via `_zone.AddPlayerAsync(...).Wait()` inside synchronous `public void` methods. SonarQube xUnit1031 flags blocking task operations in test methods. **Analysis:** xUnit runs tests without a `SynchronizationContext`, so the classic `.Wait()`/`.Result` deadlock cannot occur here — the rules headline danger does not apply. But the fix is still a genuine, low-risk improvement: `async Task` + `await` is the idiomatic async-test pattern and surfaces assertion/exception failures directly instead of wrapping them in `AggregateException`. So this is a real (if minor) cleanup, not a false positive. **Change:** method-aware conversion — only the 18 tests that actually block were converted to `async Task` with `await`; the one test with no async setup stays `void` (avoids a CS1998 async-without-await). Added `using System.Threading.Tasks;`. Scope: one test file. Build clean (0 errors, no CS1998); all 34 test cases pass unchanged. Clears 27 of the 47 open xUnit1031 findings. SonarQube rule external_roslyn:xUnit1031. Follow-up: remaining xUnit1031 live in BaseZoneTests (mixed sync/async) and a few others — deferred to keep this PR contained and verifiable.
Author
Owner

Resolved in spikersoft-backend PR #368 (merged to master). Converted the 18 blocking BroadcastToPlayersInRange tests to async Task + await (xUnit1031); all 34 cases pass, zero behavior change. Unit Tests green; merged past the non-blocking notify step. Closing.

Resolved in spikersoft-backend PR #368 (merged to `master`). Converted the 18 blocking BroadcastToPlayersInRange tests to async Task + await (xUnit1031); all 34 cases pass, zero behavior change. Unit Tests green; merged past the non-blocking notify step. Closing.
Author
Owner

Resolved in spikersoft-backend PR #366 (merged to master). Converted 18 blocking BroadcastToPlayersInRange tests to async Task + await (xUnit1031); all 34 cases pass, zero behavior change. All build/test contexts green; merged past the non-blocking notify job. Closing.

Resolved in spikersoft-backend PR #366 (merged to `master`). Converted 18 blocking BroadcastToPlayersInRange tests to async Task + await (xUnit1031); all 34 cases pass, zero behavior change. All build/test contexts green; merged past the non-blocking notify job. Closing.
Sign in to join this conversation.