Skip to content

[Internal] Tests: Refactor GatewayTests to use async/await instead of sync-over-async #5771

@kirankumarkolli

Description

@kirankumarkolli

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

  1. For methods already marked async Task but containing .Result or .Wait(): replace with await
  2. For void methods: convert to async Task, replace .Result with await, .Wait() with await
  3. Fix any AggregateException catch blocks to catch the unwrapped exception type
  4. When converting helpers to async, update ALL callers

Patterns

  • someAsyncCall().Resultawait 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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions