Skip to content

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

Open
Copilot wants to merge 7 commits intomainfrom
copilot/refactor-gateway-tests-async-await
Open

[Internal] Tests: Refactors GatewayTests to use async/await instead of sync-over-async#5772
Copilot wants to merge 7 commits intomainfrom
copilot/refactor-gateway-tests-async-await

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

GatewayTests.cs contained 81 sync-over-async anti-patterns (.Result/.Wait()) across 16+ methods, risking deadlocks and masking exceptions via AggregateException wrapping.

Changes

New async infrastructure

  • Added RetryAsync(Func<Task>) overload alongside existing Retry(Action) to support async retry lambdas

Helper methods → async

Old New
CreateDocument (static Document) async Task<Document>
CreateExecuteAndDeleteProcedure (with out param) CreateExecuteAndDeleteProcedureCoreAsync returning tuple (async can't have out params)
CreateExecuteAndDeleteCosmosProcedure CreateExecuteAndDeleteCosmosProcedureAsync
GetStoredProcedureExecutionResult GetStoredProcedureExecutionResultAsync

void test methods → async Task

  • ValidateTriggerCrud + its two [TestMethod] callers
  • ValidateUserDefinedFunctionCrud + its two [TestMethod] callers
  • ValidateUserDefinedFunctionTimeout, ValidateTriggersNameBased

Already-async methods: .Result/.Wait()await

  • ValidateStoredProcedureCrudAsync, ValidateTriggersInternal, ValidateSystemSprocInternal, ValidateStoredProceduresBlacklistingInternal, ValidateUserDefinedFunctions, ValidateStoredProcedureExecutionWithPartitionKey, ValidatePOCODocumentSerialization, ValidateCollectionQuotaTestsWithFailure

Exception handling fixed

Catch blocks that accessed AggregateException.InnerException (artifact of .Wait()/.Result) converted to catch the underlying DocumentClientException directly:

// Before
catch (AggregateException ex)
{
    Assert.AreEqual(HttpStatusCode.BadRequest, ((DocumentClientException)ex.InnerException).StatusCode);
}

// After
catch (DocumentClientException ex)
{
    Assert.AreEqual(HttpStatusCode.BadRequest, ex.StatusCode);
}

Collateral change

LinqGeneralBaselineTests.cs: updated caller of the renamed CreateExecuteAndDeleteCosmosProcedure to await GatewayTests.CreateExecuteAndDeleteCosmosProcedureAsync<int>(...).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

…to return response.Resource

Agent-Logs-Url: https://github.com/Azure/azure-cosmos-dotnet-v3/sessions/379d90d3-550e-46e2-a6a2-abc3dfed34e5

Co-authored-by: kirankumarkolli <6880899+kirankumarkolli@users.noreply.github.com>
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

Copilot AI changed the title [WIP] Refactor GatewayTests to use async/await instead of sync-over-async [Internal] Tests: Refactors GatewayTests to use async/await instead of sync-over-async Apr 10, 2026
Copilot AI requested a review from kirankumarkolli April 10, 2026 20:53
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

@kirankumarkolli kirankumarkolli marked this pull request as ready for review April 11, 2026 03:39
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

@kirankumarkolli
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
1 pipeline(s) require an authorized user to comment /azp run to run.

@kirankumarkolli
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants