Why this matters
Proper async patterns prevent deadlocks and reduce flakiness.
In async tests, return Task and await the operation; never use Thread.Sleep—use cancellation tokens or timeouts with Assert.ThrowsAsync where needed.
Proper async patterns prevent deadlocks and reduce flakiness.
Side-by-side examples engineers can pattern-match during review.
[Fact]
public void Loads(){
Thread.Sleep(2000);
var r = Client.GetAsync("/ping"); // not awaited
Assert.NotNull(r);
}[Fact]
public async Task Loads(){
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
var ex = await Assert.ThrowsAsync<HttpRequestException>(async () =>
await Client.GetAsync("/slow", cts.Token));
}public async Task TestX(){ await op(); }public void TestX(){ Thread.Sleep(1000); }From the same buckets as this rule.
Reject PRs adding real PAN/CVV in fixtures, seeds, or mocks. Only use Luhn-valid test PANs from the gateway or opaque tokens (e.g., tok_) and never include CVV. Add a check to fail if a PAN regex is matched. (PCI DSS data minimization)