diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs index ccf1b5294df35..14b059efcd438 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs @@ -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; } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/TextAnalyticsTestEnvironment.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/TextAnalyticsTestEnvironment.cs index 109c155642a71..4450e759c4f34 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/TextAnalyticsTestEnvironment.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/TextAnalyticsTestEnvironment.cs @@ -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 @@ -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 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; + } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RetryOnInternalServerErrorAttributeTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RetryOnInternalServerErrorAttributeTests.cs index 88f6eca2dbfe1..7c63def81d44a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RetryOnInternalServerErrorAttributeTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RetryOnInternalServerErrorAttributeTests.cs @@ -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);