From 1bae2326c8f4eb157a058ef964fe7ebe1743a5a0 Mon Sep 17 00:00:00 2001 From: Jose Arriaga Maldonado Date: Thu, 16 Mar 2023 15:40:26 -0700 Subject: [PATCH] Implement RetryOnInternalServerErrorAttribute --- .../tests/AbstractSummaryTests.cs | 9 ++ .../tests/AnalyzeHealthcareEntitiesTests.cs | 19 ++++ .../tests/AnalyzeOperationTests.cs | 23 ++++ .../tests/AnalyzeSentimentTests.cs | 5 +- .../tests/ExtractKeyPhrasesTests.cs | 5 +- .../tests/ExtractSummaryTests.cs | 10 ++ .../RetryOnInternalServerErrorAttribute.cs | 102 ++++++++++++++++++ .../tests/MultiLabelClassifyTests.cs | 12 +++ .../tests/OperationLiveTests.cs | 5 + .../tests/RecognizeCustomEntitiesTests.cs | 13 +++ .../tests/RecognizeEntitiesTests.cs | 5 +- .../tests/RecognizeLinkedEntitiesTests.cs | 5 +- .../tests/RecognizePiiEntitiesTests.cs | 5 +- .../tests/SingleLabelClassifyTests.cs | 12 +++ 14 files changed, 225 insertions(+), 5 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AbstractSummaryTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AbstractSummaryTests.cs index 897888d0e20a8..8bf853c45077e 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AbstractSummaryTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AbstractSummaryTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -76,6 +77,7 @@ public AbstractSummaryTests(bool isAsync, TextAnalyticsClientOptions.ServiceVers private const int AbstractiveSummarizationSentenceCount = 3; [RecordedTest] + [RetryOnInternalServerError] public async Task AbstractSummaryWithAADTest() { TextAnalyticsClient client = GetClient(useTokenCredential: true); @@ -93,6 +95,7 @@ public async Task AbstractSummaryWithAADTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AbstractSummaryBatchWithErrorTest() { TextAnalyticsClient client = GetClient(); @@ -118,6 +121,7 @@ public async Task AbstractSummaryBatchWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AbstractSummaryBatchConvenienceTest() { TextAnalyticsClient client = GetClient(); @@ -135,6 +139,7 @@ public async Task AbstractSummaryBatchConvenienceTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AbstractSummaryBatchConvenienceWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -158,6 +163,7 @@ public async Task AbstractSummaryBatchConvenienceWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AbstractSummaryBatchTest() { TextAnalyticsClient client = GetClient(); @@ -175,6 +181,7 @@ public async Task AbstractSummaryBatchTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AbstractSummaryBatchWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -198,6 +205,7 @@ public async Task AbstractSummaryBatchWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/32614")] public async Task AbstractSummaryBatchConvenienceWithAutoDetectedLanguageTest() { @@ -216,6 +224,7 @@ public async Task AbstractSummaryBatchConvenienceWithAutoDetectedLanguageTest() } [RecordedTest] + [RetryOnInternalServerError] [Ignore("https://github.com/Azure/azure-sdk-for-net/issues/32614")] public async Task AnalyzeOperationAbstractSummaryWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeHealthcareEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeHealthcareEntitiesTests.cs index 3178e1e83f8cd..5f17f3040f0cd 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeHealthcareEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeHealthcareEntitiesTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -60,6 +61,7 @@ public AnalyzeHealthcareEntitiesTests(bool isAsync, TextAnalyticsClientOptions.S }; [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesWithAADTest() { TextAnalyticsClient client = GetClient(useTokenCredential: true); @@ -79,6 +81,7 @@ public async Task AnalyzeHealthcareEntitiesWithAADTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesTest() { TextAnalyticsClient client = GetClient(); @@ -142,6 +145,7 @@ public async Task AnalyzeHealthcareEntitiesTest() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeHealthcareEntitiesWithConfidenceScoreTest() { @@ -168,6 +172,7 @@ public async Task AnalyzeHealthcareEntitiesWithConfidenceScoreTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesTestWithAssertions() { TextAnalyticsClient client = GetClient(); @@ -233,6 +238,7 @@ public async Task AnalyzeHealthcareEntitiesTestWithAssertions() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesWithLanguageTest() { TextAnalyticsClient client = GetClient(); @@ -249,6 +255,7 @@ public async Task AnalyzeHealthcareEntitiesWithLanguageTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesBatchWithErrorTest() { TextAnalyticsClient client = GetClient(); @@ -279,6 +286,7 @@ public async Task AnalyzeHealthcareEntitiesBatchWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesBatchConvenienceTest() { TextAnalyticsClient client = GetClient(); @@ -295,6 +303,7 @@ public async Task AnalyzeHealthcareEntitiesBatchConvenienceTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesBatchConvenienceWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -319,6 +328,7 @@ public async Task AnalyzeHealthcareEntitiesBatchConvenienceWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesBatchTest() { TextAnalyticsClient client = GetClient(); @@ -342,6 +352,7 @@ public async Task AnalyzeHealthcareEntitiesBatchTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesBatchWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -373,6 +384,7 @@ public async Task AnalyzeHealthcareEntitiesBatchWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] public async Task AnalyzeHealthcareEntitiesBatchWithNameTest() { @@ -401,6 +413,7 @@ public async Task AnalyzeHealthcareEntitiesBatchWithNameTest() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V3_1)] public void AnalyzeHealthcareEntitiesBatchWithNameThrows() { @@ -417,6 +430,7 @@ public void AnalyzeHealthcareEntitiesBatchWithNameThrows() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeHealthcareEntitiesPagination() { TextAnalyticsClient client = GetClient(); @@ -454,6 +468,7 @@ public async Task AnalyzeHealthcareEntitiesPagination() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeHealthcareEntitiesBatchWithFhirVersionTest() { @@ -481,6 +496,7 @@ public async Task AnalyzeHealthcareEntitiesBatchWithFhirVersionTest() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] public void AnalyzeHealthcareEntitiesBatchWithFhirVersionThrows() { @@ -497,6 +513,7 @@ public void AnalyzeHealthcareEntitiesBatchWithFhirVersionThrows() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] public void AnalyzeHealthcareEntitiesBatchWithDocumentTypeThrows() { @@ -513,6 +530,7 @@ public void AnalyzeHealthcareEntitiesBatchWithDocumentTypeThrows() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeHealthcareEntitiesBatchConvenienceWithAutoDetectedLanguageTest() { @@ -529,6 +547,7 @@ public async Task AnalyzeHealthcareEntitiesBatchConvenienceWithAutoDetectedLangu } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationAnalyzeHealthcareEntitiesWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeOperationTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeOperationTests.cs index 9fa0831428c65..1409241967771 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeOperationTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeOperationTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -37,6 +38,7 @@ public AnalyzeOperationTests(bool isAsync, TextAnalyticsClientOptions.ServiceVer }; [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithAADTest() { TextAnalyticsClient client = GetClient(useTokenCredential: true); @@ -60,6 +62,7 @@ public async Task AnalyzeOperationWithAADTest() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] public async Task AnalyzeOperationTest() { @@ -117,6 +120,7 @@ public async Task AnalyzeOperationTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithLanguageTest() { TextAnalyticsClient client = GetClient(); @@ -170,6 +174,7 @@ public async Task AnalyzeOperationWithLanguageTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithMultipleActions() { TextAnalyticsClient client = GetClient(); @@ -303,6 +308,7 @@ public async Task AnalyzeOperationWithMultipleActions() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [Ignore("issue: results in an internal server error | bug link: https://dev.azure.com/msazure/Cognitive%20Services/_workitems/edit/12413250")] public async Task AnalyzeOperationWithMultipleActionsOfSameType() @@ -423,6 +429,7 @@ public async Task AnalyzeOperationWithMultipleActionsOfSameType() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithPagination() { TextAnalyticsClient client = GetClient(); @@ -477,6 +484,7 @@ public async Task AnalyzeOperationWithPagination() } [RecordedTest] + [RetryOnInternalServerError] public void AnalyzeOperationWithErrorTest() { TextAnalyticsClient client = GetClient(); @@ -503,6 +511,7 @@ public void AnalyzeOperationWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithErrorsInDocumentTest() { TextAnalyticsClient client = GetClient(); @@ -538,6 +547,7 @@ public async Task AnalyzeOperationWithErrorsInDocumentTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithPHIDomain() { TextAnalyticsClient client = GetClient(); @@ -574,6 +584,7 @@ public async Task AnalyzeOperationWithPHIDomain() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithPiiCategories() { TextAnalyticsClient client = GetClient(); @@ -610,6 +621,7 @@ public async Task AnalyzeOperationWithPiiCategories() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -664,6 +676,7 @@ public async Task AnalyzeOperationWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationAllActionsAndDisableServiceLogs() { TextAnalyticsClient client = GetClient(); @@ -707,6 +720,7 @@ public async Task AnalyzeOperationAllActionsAndDisableServiceLogs() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationAnalyzeSentimentWithOpinionMining() { TextAnalyticsClient client = GetClient(); @@ -740,6 +754,7 @@ public async Task AnalyzeOperationAnalyzeSentimentWithOpinionMining() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] public async Task AnalyzeOperationAnalyzeHealthcareEntities() { @@ -779,6 +794,7 @@ public async Task AnalyzeOperationAnalyzeHealthcareEntities() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationAnalyzeHealthcareEntitiesWithFhirVersion() { @@ -817,6 +833,7 @@ public async Task AnalyzeOperationAnalyzeHealthcareEntitiesWithFhirVersion() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationExtractSummary() { @@ -849,6 +866,7 @@ public async Task AnalyzeOperationExtractSummary() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationAbstractSummary() { @@ -889,6 +907,7 @@ public async Task AnalyzeOperationAbstractSummary() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V3_1)] public void AnalyzeOperationAnalyzeHealthcareEntitiesActionNotSupported() { @@ -909,6 +928,7 @@ public void AnalyzeOperationAnalyzeHealthcareEntitiesActionNotSupported() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V3_1)] public void AnalyzeOperationMultiLabelClassifyActionNotSupported() { @@ -929,6 +949,7 @@ public void AnalyzeOperationMultiLabelClassifyActionNotSupported() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V3_1)] public void AnalyzeOperationRecognizeCustomEntitiesActionNotSupported() { @@ -949,6 +970,7 @@ public void AnalyzeOperationRecognizeCustomEntitiesActionNotSupported() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V3_1)] public void AnalyzeOperationSingleLabelClassifyActionNotSupported() { @@ -969,6 +991,7 @@ public void AnalyzeOperationSingleLabelClassifyActionNotSupported() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Max = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] public void AnalyzeOperationExtractSummaryActionNotSupported() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs index 914460d2d0bd7..eb6a0af1d7fdf 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeSentimentTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -437,8 +438,9 @@ public async Task AnalyzeSentimentBatchWithNullTextTest() Assert.AreEqual(exceptionMessage, ex.Message); } - [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [RecordedTest] + [RetryOnInternalServerError] + [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [Ignore("LRO not implemented")] public async Task AnalyzeSentimentWithMultipleActions() { @@ -530,6 +532,7 @@ public void AnalyzeSentimentBatchIncludeOpinionMiningThrows() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationAnalyzeSentimentWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs index 9367303b1dc01..a4562d228ff54 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractKeyPhrasesTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -197,8 +198,9 @@ public async Task ExtractKeyPhrasesBatchWithNullTextTest() Assert.AreEqual(exceptionMessage, ex.Message); } - [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [RecordedTest] + [RetryOnInternalServerError] + [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [Ignore("LRO not implemented")] public async Task ExtractKeyPhrasesWithMultipleActions() { @@ -257,6 +259,7 @@ public void ExtractKeyPhrasesBatchDisableServiceLogsThrows() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationExtractKeyPhrasesWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractSummaryTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractSummaryTests.cs index b5e7127880059..baf322fc29e9d 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractSummaryTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/ExtractSummaryTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -78,6 +79,7 @@ public ExtractSummaryTests(bool isAsync, TextAnalyticsClientOptions.ServiceVersi private const int ExtractSummaryMaxSentenceCount = 5; [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryWithAADTest() { TextAnalyticsClient client = GetClient(useTokenCredential: true); @@ -95,6 +97,7 @@ public async Task ExtractSummaryWithAADTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchWithRankOrderTest() { TextAnalyticsClient client = GetClient(); @@ -118,6 +121,7 @@ public async Task ExtractSummaryBatchWithRankOrderTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchWithErrorTest() { TextAnalyticsClient client = GetClient(); @@ -143,6 +147,7 @@ public async Task ExtractSummaryBatchWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchConvenienceTest() { TextAnalyticsClient client = GetClient(); @@ -160,6 +165,7 @@ public async Task ExtractSummaryBatchConvenienceTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchConvenienceWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -183,6 +189,7 @@ public async Task ExtractSummaryBatchConvenienceWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchTest() { TextAnalyticsClient client = GetClient(); @@ -200,6 +207,7 @@ public async Task ExtractSummaryBatchTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchWithStatisticsTest() { TextAnalyticsClient client = GetClient(); @@ -223,6 +231,7 @@ public async Task ExtractSummaryBatchWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task ExtractSummaryBatchConvenienceWithAutoDetectedLanguageTest() { TextAnalyticsClient client = GetClient(); @@ -240,6 +249,7 @@ public async Task ExtractSummaryBatchConvenienceWithAutoDetectedLanguageTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationExtractSummaryWithAutoDetectedLanguageTest() { TextAnalyticsClient client = GetClient(); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs new file mode 100644 index 0000000000000..cc29d8c886934 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/Infrastructure/RetryOnInternalServerErrorAttribute.cs @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using NUnit.Framework; +using NUnit.Framework.Interfaces; +using NUnit.Framework.Internal; +using NUnit.Framework.Internal.Commands; + +namespace Azure.AI.TextAnalytics.Tests.Infrastructure +{ + /// + /// Attribute used to specify that a test must be retried in the specific case of a known transient issue where the + /// server returns a successful 200 OK response status but reports an internal server error in the response body + /// for one or more text analysis tasks. If the test continues to fail due to this particular issue after reaching + /// the retry limit, the test result is marked as inconclusive. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public class RetryOnInternalServerErrorAttribute : NUnitAttribute, IRepeatTest + { + /// + /// The maximum number of times that the test will be retried. + /// + private const int RetryLimit = 3; + + #region IRepeatTest Members + + /// + /// Wrap a command and return the result. + /// + public TestCommand Wrap(TestCommand command) + { + return new RetryOnInternalServerErrorCommand(command, RetryLimit); + } + + #endregion + + /// + /// The test command for the . + /// + public class RetryOnInternalServerErrorCommand : DelegatingTestCommand + { + private readonly int _retryLimit; + + /// + /// Initializes a new instance of the class. + /// + public RetryOnInternalServerErrorCommand(TestCommand innerCommand, int retryLimit) + : base(innerCommand) + { + _retryLimit = retryLimit; + } + + /// + /// Runs the test, saving a in the supplied . + /// + public override TestResult Execute(TestExecutionContext context) + { + int count = _retryLimit; + bool retry = true; + + while (retry) + { + try + { + context.CurrentResult = innerCommand.Execute(context); + retry = false; + } + catch (RequestFailedException ex) when (ShouldRetry(ex)) + { + if (count-- > 0) + { + // Clear result for retry. + context.CurrentResult = context.CurrentTest.MakeTestResult(); + context.CurrentRepeatCount++; + } + else + { + context.CurrentResult = context.CurrentTest.MakeTestResult(); + context.CurrentResult.SetResult(ResultState.Inconclusive); + retry = false; + } + } + catch (Exception ex) + { + context.CurrentResult ??= context.CurrentTest.MakeTestResult(); + context.CurrentResult.RecordException(ex); + retry = false; + } + } + + return context.CurrentResult; + } + + /// + /// Indicates whether the encountered exception corresponds to the issue in question. + /// + private static bool ShouldRetry(RequestFailedException ex) => + ex.Status == 200 && ex.ErrorCode == "InternalServerError"; + } + } +} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/MultiLabelClassifyTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/MultiLabelClassifyTests.cs index 89595b2a5a491..d1aa094299041 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/MultiLabelClassifyTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/MultiLabelClassifyTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -43,6 +44,7 @@ public MultiLabelClassifyTests(bool isAsync, TextAnalyticsClientOptions.ServiceV }; [RecordedTest] + [RetryOnInternalServerError] public async Task MultiLabelClassifyWithDisableServiceLogs() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -67,6 +69,7 @@ public async Task MultiLabelClassifyWithDisableServiceLogs() } [RecordedTest] + [RetryOnInternalServerError] public async Task MultiLabelClassifyBatchWithErrorTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -102,6 +105,7 @@ public async Task MultiLabelClassifyBatchWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task MultiLabelClassifyBatchConvenienceTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -129,6 +133,7 @@ public async Task MultiLabelClassifyBatchConvenienceTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task MultiLabelClassifyBatchConvenienceWithStatisticsTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -161,6 +166,7 @@ public async Task MultiLabelClassifyBatchConvenienceWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task MultiLabelClassifyBatchTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -188,6 +194,7 @@ public async Task MultiLabelClassifyBatchTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task MultiLabelClassifyBatchWithStatisticsTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -220,6 +227,7 @@ public async Task MultiLabelClassifyBatchWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] [Ignore("Issue https://github.com/Azure/azure-sdk-for-net/issues/25152")] public async Task MultiLabelClassifyWithMultipleActions() { @@ -258,6 +266,7 @@ public async Task MultiLabelClassifyWithMultipleActions() } [RecordedTest] + [RetryOnInternalServerError] public async Task StartMultiLabelClassify() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -272,6 +281,7 @@ public async Task StartMultiLabelClassify() } [RecordedTest] + [RetryOnInternalServerError] public async Task StartMultiLabelClassifyWithName() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -290,6 +300,7 @@ public async Task StartMultiLabelClassifyWithName() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task MultiLabelClassifyBatchConvenienceWithAutoDetectedLanguageTest() { @@ -308,6 +319,7 @@ public async Task MultiLabelClassifyBatchConvenienceWithAutoDetectedLanguageTest } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationMultiLabelClassifyWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/OperationLiveTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/OperationLiveTests.cs index 166d7d018d62d..548d76ee458dc 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/OperationLiveTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/OperationLiveTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -19,6 +20,7 @@ public OperationLiveTests(bool isAsync, TextAnalyticsClientOptions.ServiceVersio #region Analyze [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationCanPollFromNewObject() { TextAnalyticsClient client = GetClient(out var nonInstrumentedClient); @@ -48,6 +50,7 @@ public async Task AnalyzeOperationCanPollFromNewObject() } [RecordedTest] + [RetryOnInternalServerError] public async Task AnalyzeOperationConvenienceCanPollFromNewObject() { TextAnalyticsClient client = GetClient(out var nonInstrumentedClient); @@ -75,6 +78,7 @@ public async Task AnalyzeOperationConvenienceCanPollFromNewObject() #region Healthcare [RecordedTest] + [RetryOnInternalServerError] public async Task HealthcareOperationCanPollFromNewObject() { TextAnalyticsClient client = GetClient(out var nonInstrumentedClient); @@ -99,6 +103,7 @@ public async Task HealthcareOperationCanPollFromNewObject() } [RecordedTest] + [RetryOnInternalServerError] public async Task HealthcareOperationConvenienceCanPollFromNewObject() { TextAnalyticsClient client = GetClient(out var nonInstrumentedClient); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeCustomEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeCustomEntitiesTests.cs index 6d80b5c65fa6e..0dd501cabc8bb 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeCustomEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeCustomEntitiesTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -71,6 +72,7 @@ public RecognizeCustomEntitiesTests(bool isAsync, TextAnalyticsClientOptions.Ser }; [RecordedTest] + [RetryOnInternalServerError] public async Task RecognizeCustomEntitiesWithAADTest() { TextAnalyticsClient client = GetClient(useTokenCredential: true, useStaticResource: true); @@ -95,6 +97,7 @@ public async Task RecognizeCustomEntitiesWithAADTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task RecognizeCustomEntitiesTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -119,6 +122,7 @@ public async Task RecognizeCustomEntitiesTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task RecognizeCustomEntitiesWithLanguageTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -148,6 +152,7 @@ public async Task RecognizeCustomEntitiesWithLanguageTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task RecognizeCustomEntitiesBatchWithErrorTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -183,6 +188,7 @@ public async Task RecognizeCustomEntitiesBatchWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task RecognizeCustomEntitiesBatchConvenienceTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -206,6 +212,7 @@ public async Task RecognizeCustomEntitiesBatchConvenienceTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task RecognizeCustomEntitiesBatchTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -234,6 +241,7 @@ public async Task RecognizeCustomEntitiesBatchTest() } [RecordedTest] + [RetryOnInternalServerError] public void RecognizeCustomEntitiesBatchWithNullIdTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -252,6 +260,7 @@ public void RecognizeCustomEntitiesBatchWithNullIdTest() } [RecordedTest] + [RetryOnInternalServerError] [Ignore("Issue https://github.com/Azure/azure-sdk-for-net/issues/25152")] public async Task RecognizeCustomEntitiesWithMultipleActions() { @@ -290,6 +299,7 @@ public async Task RecognizeCustomEntitiesWithMultipleActions() } [RecordedTest] + [RetryOnInternalServerError] public async Task StartRecognizeCustomEntities() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -311,6 +321,7 @@ public async Task StartRecognizeCustomEntities() } [RecordedTest] + [RetryOnInternalServerError] public async Task StartRecognizeCustomEntitiesWithName() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -336,6 +347,7 @@ public async Task StartRecognizeCustomEntitiesWithName() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task RecognizeCustomEntitiesBatchConvenienceWithAutoDetectedLanguageTest() { @@ -354,6 +366,7 @@ public async Task RecognizeCustomEntitiesBatchConvenienceWithAutoDetectedLanguag } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationRecognizeCustomEntitiesWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs index ec8c4487a3a04..f99c1f2d5465c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeEntitiesTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -229,8 +230,9 @@ public async Task RecognizeEntitiesBatchWithNullTextTest() Assert.AreEqual(exceptionMessage, ex.Message); } - [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [RecordedTest] + [RetryOnInternalServerError] + [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [Ignore("LRO not implemented")] public async Task RecognizeEntitiesWithMultipleActions() { @@ -464,6 +466,7 @@ public async Task RecognizeEntitiesBatchWithResolutionsTest() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationRecognizeEntitiesWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs index 987612a1061d2..2e13961bf575a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizeLinkedEntitiesTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -211,8 +212,9 @@ public async Task RecognizeLinkedEntitiesBatchWithNullTextTest() Assert.AreEqual(exceptionMessage, ex.Message); } - [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [RecordedTest] + [RetryOnInternalServerError] + [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [Ignore("LRO not implemented")] public async Task RecognizeLinkedEntitiesWithMultipleActions() { @@ -272,6 +274,7 @@ public void RecognizeLinkedEntitiesBatchDisableServiceLogsThrows() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationRecognizeLinkedEntitiesWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizePiiEntitiesTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizePiiEntitiesTests.cs index b8656b8827c56..2ef80a70af618 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizePiiEntitiesTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/RecognizePiiEntitiesTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -233,8 +234,9 @@ public async Task RecognizePiiEntitiesBatchWitCategoryTest() ValidateBatchDocumentsResult(results, expectedOutput); } - [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [RecordedTest] + [RetryOnInternalServerError] + [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_05_01)] [Ignore("LRO not implemented")] public async Task RecognizePiiEntitiesWithMultipleActions() { @@ -272,6 +274,7 @@ public async Task RecognizePiiEntitiesWithMultipleActions() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationRecognizePiiEntitiesWithAutoDetectedLanguageTest() { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SingleLabelClassifyTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SingleLabelClassifyTests.cs index 291833720081d..7bec8d6d1367a 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SingleLabelClassifyTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/SingleLabelClassifyTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Azure.AI.TextAnalytics.Tests.Infrastructure; using Azure.Core.TestFramework; using NUnit.Framework; @@ -43,6 +44,7 @@ public SingleLabelClassifyTests(bool isAsync, TextAnalyticsClientOptions.Service }; [RecordedTest] + [RetryOnInternalServerError] public async Task SingleLabelClassifyWithDisableServiceLogs() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -67,6 +69,7 @@ public async Task SingleLabelClassifyWithDisableServiceLogs() } [RecordedTest] + [RetryOnInternalServerError] public async Task SingleLabelClassifyBatchWithErrorTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -102,6 +105,7 @@ public async Task SingleLabelClassifyBatchWithErrorTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task SingleLabelClassifyBatchConvenienceTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -129,6 +133,7 @@ public async Task SingleLabelClassifyBatchConvenienceTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task SingleLabelClassifyBatchConvenienceWithStatisticsTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -161,6 +166,7 @@ public async Task SingleLabelClassifyBatchConvenienceWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task SingleLabelClassifyBatchTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -188,6 +194,7 @@ public async Task SingleLabelClassifyBatchTest() } [RecordedTest] + [RetryOnInternalServerError] public async Task SingleLabelClassifyBatchWithStatisticsTest() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -220,6 +227,7 @@ public async Task SingleLabelClassifyBatchWithStatisticsTest() } [RecordedTest] + [RetryOnInternalServerError] [Ignore("Issue https://github.com/Azure/azure-sdk-for-net/issues/25152")] public async Task SingleLabelClassifyWithMultipleActions() { @@ -257,6 +265,7 @@ public async Task SingleLabelClassifyWithMultipleActions() } [RecordedTest] + [RetryOnInternalServerError] public async Task StartSingleLabelClassify() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -271,6 +280,7 @@ public async Task StartSingleLabelClassify() } [RecordedTest] + [RetryOnInternalServerError] public async Task StartSingleLabelClassifyWithName() { TextAnalyticsClient client = GetClient(useStaticResource: true); @@ -289,6 +299,7 @@ public async Task StartSingleLabelClassifyWithName() } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task SingleLabelClassifyBatchConvenienceWithAutoDetectedLanguageTest() { @@ -307,6 +318,7 @@ public async Task SingleLabelClassifyBatchConvenienceWithAutoDetectedLanguageTes } [RecordedTest] + [RetryOnInternalServerError] [ServiceVersion(Min = TextAnalyticsClientOptions.ServiceVersion.V2022_10_01_Preview)] public async Task AnalyzeOperationSingleLabelClassifyWithAutoDetectedLanguageTest() {