Skip to content

Commit 08af269

Browse files
authored
[Text Analytics] Implement IsEnvironmentReadyAsync (#35453)
1 parent 321d9ac commit 08af269

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,21 @@ private static bool ShouldRetry(TestExecutionContext context)
4040
&& message.Contains("Status: 200 (OK)")
4141
&& message.Contains("ErrorCode: InternalServerError");
4242

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

50-
return failedToProcessTaskTransientError || invalidTaskTypeTransientError;
50+
// A known transient issue where the server fails to process a request and does not provide more context.
51+
bool internalServerTransientError =
52+
message.Contains("Azure.RequestFailedException")
53+
&& message.Contains("Internal Server Error.")
54+
&& message.Contains("Status: 200 (OK)")
55+
&& message.Contains("ErrorCode: InternalServerError");
56+
57+
return failedToProcessTaskTransientError || invalidTaskTypeTransientError || internalServerTransientError;
5158
}
5259
}
5360
}

sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/TextAnalyticsTestEnvironment.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System;
5+
using System.Threading.Tasks;
46
using Azure.Core.TestFramework;
57

68
namespace Azure.AI.TextAnalytics.Tests
@@ -20,5 +22,24 @@ public class TextAnalyticsTestEnvironment: TestEnvironment
2022
public string MultiClassificationDeploymentName => GetRecordedVariable("TEXTANALYTICS_MULTI_CATEGORY_CLASSIFY_DEPLOYMENT_NAME");
2123
public string RecognizeCustomEntitiesProjectName => GetRecordedVariable("TEXTANALYTICS_CUSTOM_ENTITIES_PROJECT_NAME");
2224
public string RecognizeCustomEntitiesDeploymentName => GetRecordedVariable("TEXTANALYTICS_CUSTOM_ENTITIES_DEPLOYMENT_NAME");
25+
26+
protected override async ValueTask<bool> IsEnvironmentReadyAsync()
27+
{
28+
// Check that the dynamic resource is ready.
29+
Uri endpoint = new(Endpoint);
30+
AzureKeyCredential credential = new(ApiKey);
31+
TextAnalyticsClient client = new(endpoint, credential);
32+
33+
try
34+
{
35+
await client.DetectLanguageAsync("The dynamic resource is ready.");
36+
}
37+
catch (RequestFailedException e) when (e.Status == 401)
38+
{
39+
return false;
40+
}
41+
42+
return true;
43+
}
2344
}
2445
}

sdk/textanalytics/Azure.AI.TextAnalytics/tests/RetryOnInternalServerErrorAttributeTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,24 @@ namespace Azure.AI.TextAnalytics.Tests
1414
public class RetryOnInternalServerErrorAttributeTests
1515
{
1616
private const string FailedToProcessTaskExceptionMessage =
17-
"Failed to process task after several retry,"
18-
+ " Status: 200 (OK),"
19-
+ " ErrorCode: InternalServerError";
17+
"Failed to process task after several retry"
18+
+ ", Status: 200 (OK)"
19+
+ ", ErrorCode: InternalServerError";
2020

2121
private const string InvalidTaskTypeExceptionMessage =
22-
"Invalid Task Type,"
23-
+ " Status: 500 (Internal Server Error),"
24-
+ " ErrorCode: InternalServerError";
22+
"Invalid Task Type"
23+
+ ", Status: 500 (Internal Server Error)"
24+
+ ", ErrorCode: InternalServerError";
25+
26+
private const string InternalServerErrorExceptionMessage =
27+
"Internal Server Error."
28+
+ ", Status: 200 (OK)"
29+
+ ", ErrorCode: InternalServerError";
2530

2631
[Test]
2732
[TestCase(FailedToProcessTaskExceptionMessage)]
2833
[TestCase(InvalidTaskTypeExceptionMessage)]
34+
[TestCase(InternalServerErrorExceptionMessage)]
2935
public void FailingTestIsRetried(string exceptionMessage)
3036
{
3137
RequestFailedException exception = new(200, exceptionMessage, "InternalServerError", null);

0 commit comments

Comments
 (0)