< Summary

Class:Microsoft.Azure.Batch.Common.RetryPolicyCommon
Assembly:Microsoft.Azure.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Common\RetryPolicyCommon.cs
Covered lines:23
Uncovered lines:1
Coverable lines:24
Total lines:76
Line coverage:95.8% (23 of 24)
Covered branches:19
Total branches:22
Branch coverage:86.3% (19 of 22)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ShouldRetry(...)-94.74%83.33%
ValidateArguments(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\batch\Microsoft.Azure.Batch\src\Common\RetryPolicyCommon.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License. See License.txt in the project root for license information.
 3
 4namespace Microsoft.Azure.Batch.Common
 5{
 6    using System;
 7
 8    internal static class RetryPolicyCommon
 9    {
 10        internal static bool ShouldRetry(Exception exception, OperationContext operationContext, int maxRetries)
 11        {
 12            bool shouldRetry;
 5613            int currentRetryCount = operationContext.RequestResults.Count - 1;
 14
 5615            if (currentRetryCount < maxRetries)
 16            {
 4717                BatchException batchException = exception as BatchException;
 4718                if (batchException != null)
 19                {
 420                    int statusCode = (int)batchException.RequestInformation.HttpStatusCode;
 21
 422                    if ((statusCode >= 400 && statusCode < 500
 423                        && statusCode != 408 // Timeout
 424                        && statusCode != 429 // Too many reqeuests
 425                        )
 426                        || statusCode == 501 // Not Implemented
 427                        || statusCode == 505 // Version Not Supported
 428                        )
 29                    {
 030                        shouldRetry = false;
 31                    }
 32                    else
 33                    {
 434                        shouldRetry = true;
 35                    }
 36                }
 37                else
 38                {
 39                    //Note that we use a disallow list here in order to have the most robust retry policy --
 40                    //attempting to guess all the possible exception types thrown by the network stack to craft a
 41                    //white list is error prone and so we avoid it.
 4342                    if (exception is Microsoft.Rest.ValidationException)
 43                    {
 44                        //TODO: Consider adding SystemException to disallow list, but SystemException includes TimeoutEx
 245                        shouldRetry = false;
 46                    }
 47                    else
 48                    {
 49                        //Retry on all other exceptions which aren't a BatchException since those exceptions
 50                        //mean we haven't heard back from the server
 4151                        shouldRetry = true;
 52                    }
 53                }
 54            }
 55            else
 56            {
 957                shouldRetry = false; //We are out of retries to perform so we will not retry
 58            }
 59
 5660            return shouldRetry;
 61        }
 62
 63        internal static void ValidateArguments(TimeSpan deltaBackoff, int maxRetries)
 64        {
 67865            if (deltaBackoff < TimeSpan.Zero)
 66            {
 267                throw new ArgumentOutOfRangeException(nameof(deltaBackoff));
 68            }
 69
 67670            if (maxRetries < 0)
 71            {
 272                throw new ArgumentOutOfRangeException(nameof(maxRetries));
 73            }
 67474        }
 75    }
 76}