Summary
GatewayTests.cs contains 81 sync-over-async anti-patterns (~60 .Result, ~10 .Wait()) — the largest offender in the test suite. These should be converted to proper async/await.
File
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewayTests.cs
What to fix
Key methods (16 identified):
ValidateStoredProceduresInternal: void, 24 sync calls — convert to async Task
ValidateTriggersInternal: already async Task, 11 .Result calls — replace with await
ValidatePOCODocumentSerialization: already async Task, 7 .Result calls
ValidateStoredProcedureCrudAsync: already async Task, 4 .Result calls
ValidateStoredProceduresBlacklistingInternal: already async Task, 3 sync calls
ValidateUserDefinedFunctions: already async Task, 4 .Result calls
ValidateStoredProcedureExecutionWithPartitionKey: already async Task, 3 .Result calls
ValidateTriggersNameBased: void, 4 sync calls
ValidateUserDefinedFunctionTimeout: void, 2 .Result calls
- Plus ~7 more helper methods with 1-4 sync calls each
Fix approach
- For methods already marked
async Task but containing .Result or .Wait(): replace with await
- For void methods: convert to
async Task, replace .Result with await, .Wait() with await
- Fix any
AggregateException catch blocks to catch the unwrapped exception type
- When converting helpers to async, update ALL callers
Patterns
someAsyncCall().Result → await someAsyncCall()
someAsyncCall().Result.Property → (await someAsyncCall()).Property
someAsyncCall().Wait() → await someAsyncCall()
public void TestMethod() → public async Task TestMethod()
catch (AggregateException ex) { ... ex.InnerException ... } → catch (SpecificException)
Branch naming
Use users/copilot/fix-sync-over-async-gatewaytests
PR title format
[Internal] Tests: Refactors GatewayTests to use async/await instead of sync-over-async
Notes
Summary
GatewayTests.cs contains 81 sync-over-async anti-patterns (~60
.Result, ~10.Wait()) — the largest offender in the test suite. These should be converted to proper async/await.File
Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/GatewayTests.csWhat to fix
Key methods (16 identified):
ValidateStoredProceduresInternal: void, 24 sync calls — convert to async TaskValidateTriggersInternal: already async Task, 11.Resultcalls — replace with awaitValidatePOCODocumentSerialization: already async Task, 7.ResultcallsValidateStoredProcedureCrudAsync: already async Task, 4.ResultcallsValidateStoredProceduresBlacklistingInternal: already async Task, 3 sync callsValidateUserDefinedFunctions: already async Task, 4.ResultcallsValidateStoredProcedureExecutionWithPartitionKey: already async Task, 3.ResultcallsValidateTriggersNameBased: void, 4 sync callsValidateUserDefinedFunctionTimeout: void, 2.ResultcallsFix approach
async Taskbut containing.Resultor.Wait(): replace withawaitasync Task, replace.Resultwithawait,.Wait()withawaitAggregateExceptioncatch blocks to catch the unwrapped exception typePatterns
someAsyncCall().Result→await someAsyncCall()someAsyncCall().Result.Property→(await someAsyncCall()).PropertysomeAsyncCall().Wait()→await someAsyncCall()public void TestMethod()→public async Task TestMethod()catch (AggregateException ex) { ... ex.InnerException ... }→catch (SpecificException)Branch naming
Use
users/copilot/fix-sync-over-async-gatewaytestsPR title format
[Internal] Tests: Refactors GatewayTests to use async/await instead of sync-over-asyncNotes
.Resultand.Wait()occurrencesawaitcalls AND.Resultcalls — fix only the.ResultcallsSynchronizationContextTests.csdotnet build Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Microsoft.Azure.Cosmos.EmulatorTests.csproj --no-restore -c Debug