Skip to content

Commit

Permalink
[Text Analytics] Implement IsEnvironmentReadyAsync (#35453)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseharriaga authored Apr 11, 2023
1 parent 321d9ac commit 08af269
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ private static bool ShouldRetry(TestExecutionContext context)
&& message.Contains("Status: 200 (OK)")
&& message.Contains("ErrorCode: InternalServerError");

// A known transient issue where the server appears to be unable to process a valid task.
// A known transient issue where the server appears to be unable to process a valid text analysis task.
bool invalidTaskTypeTransientError =
message.Contains("Azure.RequestFailedException")
&& message.Contains("Invalid Task Type")
&& message.Contains("Status: 500 (Internal Server Error)")
&& message.Contains("ErrorCode: InternalServerError");

return failedToProcessTaskTransientError || invalidTaskTypeTransientError;
// A known transient issue where the server fails to process a request and does not provide more context.
bool internalServerTransientError =
message.Contains("Azure.RequestFailedException")
&& message.Contains("Internal Server Error.")
&& message.Contains("Status: 200 (OK)")
&& message.Contains("ErrorCode: InternalServerError");

return failedToProcessTaskTransientError || invalidTaskTypeTransientError || internalServerTransientError;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading.Tasks;
using Azure.Core.TestFramework;

namespace Azure.AI.TextAnalytics.Tests
Expand All @@ -20,5 +22,24 @@ public class TextAnalyticsTestEnvironment: TestEnvironment
public string MultiClassificationDeploymentName => GetRecordedVariable("TEXTANALYTICS_MULTI_CATEGORY_CLASSIFY_DEPLOYMENT_NAME");
public string RecognizeCustomEntitiesProjectName => GetRecordedVariable("TEXTANALYTICS_CUSTOM_ENTITIES_PROJECT_NAME");
public string RecognizeCustomEntitiesDeploymentName => GetRecordedVariable("TEXTANALYTICS_CUSTOM_ENTITIES_DEPLOYMENT_NAME");

protected override async ValueTask<bool> IsEnvironmentReadyAsync()
{
// Check that the dynamic resource is ready.
Uri endpoint = new(Endpoint);
AzureKeyCredential credential = new(ApiKey);
TextAnalyticsClient client = new(endpoint, credential);

try
{
await client.DetectLanguageAsync("The dynamic resource is ready.");
}
catch (RequestFailedException e) when (e.Status == 401)
{
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ namespace Azure.AI.TextAnalytics.Tests
public class RetryOnInternalServerErrorAttributeTests
{
private const string FailedToProcessTaskExceptionMessage =
"Failed to process task after several retry,"
+ " Status: 200 (OK),"
+ " ErrorCode: InternalServerError";
"Failed to process task after several retry"
+ ", Status: 200 (OK)"
+ ", ErrorCode: InternalServerError";

private const string InvalidTaskTypeExceptionMessage =
"Invalid Task Type,"
+ " Status: 500 (Internal Server Error),"
+ " ErrorCode: InternalServerError";
"Invalid Task Type"
+ ", Status: 500 (Internal Server Error)"
+ ", ErrorCode: InternalServerError";

private const string InternalServerErrorExceptionMessage =
"Internal Server Error."
+ ", Status: 200 (OK)"
+ ", ErrorCode: InternalServerError";

[Test]
[TestCase(FailedToProcessTaskExceptionMessage)]
[TestCase(InvalidTaskTypeExceptionMessage)]
[TestCase(InternalServerErrorExceptionMessage)]
public void FailingTestIsRetried(string exceptionMessage)
{
RequestFailedException exception = new(200, exceptionMessage, "InternalServerError", null);
Expand Down

0 comments on commit 08af269

Please sign in to comment.