Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle RateLimitException and Request Timeout in Export Operation #4742

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,29 @@ public async Task GivenSearchHadIssues_WhenExecuted_ThenIssuesAreRecorded()
Assert.True(_exportJobRecord.Issues.Contains(issue));
}

[Fact]
public async Task GivenSearchServiceThrowsRequestTimeoutException_WhenExecuted_ThenExceptionIsCaughtAndHandled()
{
// Arrange
string errorMessage = "The execution timeout expired while interacting with CosmosDB.";
_searchService.SearchAsync(
Arg.Any<string>(),
Arg.Any<IReadOnlyList<Tuple<string, string>>>(),
_cancellationToken,
true)
.Returns<SearchResult>(x =>
{
throw new RequestTimeoutException(errorMessage);
});

await _exportJobTask.ExecuteAsync(_exportJobRecord, _weakETag, _cancellationToken);

Assert.NotNull(_lastExportJobOutcome);
Assert.Equal(OperationStatus.Failed, _lastExportJobOutcome.JobRecord.Status);
Assert.Contains(errorMessage, _lastExportJobOutcome.JobRecord.FailureDetails.FailureDetails);
Assert.Equal(HttpStatusCode.InternalServerError, _lastExportJobOutcome.JobRecord.FailureDetails.FailureStatusCode);
}

[Fact]
public async Task GivenNumberOfSearch_WhenExecuted_ThenItShouldCommitOneLastTime()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public async Task GivenAnExceptionWithRequestExceededStatusCode_WhenProcessing_T
await Assert.ThrowsAsync<RequestRateExceededException>(async () => await _cosmosResponseProcessor.ProcessErrorResponseAsync(CosmosResponseMessage.Create(response), CancellationToken.None));
}

[Fact]
public async Task GivenARequestTimeoutStatusCode_WhenProcessErrorResponseAsyncCalled_ThenRequestTimeoutExceptionShouldBeThrown()
{
ResponseMessage response = CreateResponseException("The execution timeout expired while interacting with CosmosDB.", HttpStatusCode.RequestTimeout);

await Assert.ThrowsAsync<RequestTimeoutException>(async () => await _cosmosResponseProcessor.ProcessErrorResponseAsync(CosmosResponseMessage.Create(response), CancellationToken.None));
}

[Fact]
public async Task GivenAnExceptionWithSpecificMessage_WhenProcessing_ThenExceptionShouldThrow()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public async Task ProcessErrorResponseAsync(HttpStatusCode statusCode, Headers h
exception = new Microsoft.Health.Fhir.Core.Exceptions.CustomerManagedKeyException(GetCustomerManagedKeyErrorMessage(subStatusValue.Value));
}
}
else if (statusCode == HttpStatusCode.RequestTimeout)
{
exception = new Microsoft.Health.Fhir.Core.Exceptions.RequestTimeoutException(Resources.CosmosDBRequestTimeout, exception);
}

if (exception != null)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.Health.Fhir.CosmosDb/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/Microsoft.Health.Fhir.CosmosDb/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
</data>
<data name="CmkDefaultError" xml:space="preserve">
<value>There was an error using the customer-managed key.</value>
</data>
<data name="CosmosDBRequestTimeout" xml:space="preserve">
<value>The execution timeout expired while interacting with CosmosDB.</value>
</data>
<data name="IncludeIterateNotSupported" xml:space="preserve">
<value>_include:iterate and _revinclude:iterate are not supported.</value>
Expand All @@ -173,5 +176,5 @@
</data>
<data name="NotAbleToExecuteQuery" xml:space="preserve">
<value>Not able to execute a query. Retry the operation.</value>
</data>
</root>
</data>
</root>
Loading