Skip to content

Commit 534c395

Browse files
committed
Responding to review feedback
1 parent 34bd81a commit 534c395

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Common/Commands.Common.Authentication.Test/ClientFactoryHandlerTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public void AddsAppropriateRetryPolicy()
9898
account,
9999
AzureEnvironment.PublicEnvironments["AzureCloud"]
100100
);
101-
102101
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory(userAccount, Guid.NewGuid().ToString());
103102
var factory = new ClientFactory();
104103
factory.AddHandler(new RetryTestHandler());
@@ -116,8 +115,6 @@ public void AddsAppropriateRetryPolicy()
116115
autoRestHandler.MaxTries = 0;
117116
task = autorestClient.ResourceGroups.ListWithHttpMessagesAsync();
118117
Assert.Throws<TaskCanceledException>(() => task.ConfigureAwait(false).GetAwaiter().GetResult());
119-
120-
121118
}
122119

123120
private CancelRetryHandler EnsureHyakRetryPolicy<T>( Hyak.Common.ServiceClient<T> client) where T: Hyak.Common.ServiceClient<T>

src/Common/Commands.Common.Authentication/Factories/CancelRetryHandler.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Factories
2626
/// </summary>
2727
public class CancelRetryHandler : DelegatingHandler, ICloneable
2828
{
29+
const string TestModeVariableKey = "Azure_Test_Mode", TestModeVariableValue="Record";
2930
public CancelRetryHandler()
3031
{
3132
WaitInterval = TimeSpan.Zero;
@@ -53,13 +54,22 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
5354
}
5455
catch (TaskCanceledException) when (tries++ < MaxTries)
5556
{
56-
Thread.Sleep(WaitInterval);
57+
SleepIfRunningLive(WaitInterval);
5758
}
5859
}
5960
}
6061
while (true);
6162
}
6263

64+
void SleepIfRunningLive(TimeSpan timeSpan)
65+
{
66+
var testModeSetting = Environment.GetEnvironmentVariable(TestModeVariableKey);
67+
if (string.IsNullOrWhiteSpace(testModeSetting) || !string.Equals(TestModeVariableValue, testModeSetting, StringComparison.OrdinalIgnoreCase))
68+
{
69+
Thread.Sleep(timeSpan);
70+
}
71+
}
72+
6373
public object Clone()
6474
{
6575
return new CancelRetryHandler(WaitInterval, MaxTries);

src/Common/Commands.Common.Authentication/Factories/ClientFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public virtual TClient CreateClient<TClient>(IAzureContextContainer profile, IAz
189189
}
190190

191191
return client;
192-
193192
}
194193

195194
public virtual TClient CreateCustomClient<TClient>(params object[] parameters) where TClient : ServiceClient<TClient>

0 commit comments

Comments
 (0)