Tests: unchecked SemaphoreSlim.WaitAsync(timeout) results let waits time out silently #221

Closed
opened 2026-11-09 12:59:15 -05:00 by dohertj2 · 1 comment
Owner

SemaphoreSlim.WaitAsync(TimeSpan) returns false on timeout instead of throwing. Test helpers in src/ZB.MOM.WW.MxGateway.Tests that await sem.WaitAsync(timeout) without checking the result silently continue after a timeout, so a test can pass while the event it waited for never happened (found while writing the #205 lease-monitor tests; fixed only in that helper). Grep the Tests project for unchecked WaitAsync( with a timeout and make each assert (Assert.True(await ...)), then mutation-check one.

`SemaphoreSlim.WaitAsync(TimeSpan)` returns `false` on timeout instead of throwing. Test helpers in `src/ZB.MOM.WW.MxGateway.Tests` that `await sem.WaitAsync(timeout)` without checking the result silently continue after a timeout, so a test can pass while the event it waited for never happened (found while writing the #205 lease-monitor tests; fixed only in that helper). Grep the Tests project for unchecked `WaitAsync(` with a timeout and make each assert (`Assert.True(await ...)`), then mutation-check one.
dohertj2 added the area:teststype:testpriority:p3 labels 2026-11-09 12:59:15 -05:00
Author
Owner

Fixed on main b9913188: the only unchecked timed SemaphoreSlim.WaitAsync calls in MxGateway.Tests were two start-gate waits in GatewaySessionTests (concurrent-dispose, subscriber-cap) — both now Assert.True. All other timed waits were already checked or token-only. Mutation: 200 ms gate with one permit short — old code passed silently, fixed code fails 'Timed out at the start gate'. Worker.Tests has similar patterns — filed separately. Evidence: NonWindows.slnx 0 warnings/0 errors; MxGateway.Tests 1395 passed / 2 skipped / 0 failed; converted classes 10 consecutive runs, 15/15 each.

Fixed on main b9913188: the only unchecked timed SemaphoreSlim.WaitAsync calls in MxGateway.Tests were two start-gate waits in GatewaySessionTests (concurrent-dispose, subscriber-cap) — both now Assert.True. All other timed waits were already checked or token-only. Mutation: 200 ms gate with one permit short — old code passed silently, fixed code fails 'Timed out at the start gate'. Worker.Tests has similar patterns — filed separately. Evidence: NonWindows.slnx 0 warnings/0 errors; MxGateway.Tests 1395 passed / 2 skipped / 0 failed; converted classes 10 consecutive runs, 15/15 each.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#221