提交 31084592 编写于 作者: C Charles Stoner

Remove Retry timeout parameter

上级 f1056adf
using System;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.VisualStudio.IntegrationTest.Utilities
......@@ -6,122 +8,93 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities
public static class Helper
{
/// <summary>
/// This method will retry the action represented by the 'action' argument, up to 'timeout'
/// This method will retry the action represented by the 'action' argument,
/// milliseconds, waiting 'delay' milliseconds after each retry. If a given retry returns a value
/// other than default(T), this value is returned.
/// </summary>
/// <param name="action">the action to retry</param>
/// <param name="delay">the amount of time to wait between retries in milliseconds</param>
/// <param name="timeout">the max amount of time to spend retrying in milliseconds</param>
/// <typeparam name="T">type of return value</typeparam>
/// <returns>the return value of 'action'</returns>
public static T Retry<T>(Func<T> action, int delay, int timeout)
=> Retry(action, TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(timeout));
public static T Retry<T>(Func<T> action, int delay)
=> Retry(action, TimeSpan.FromMilliseconds(delay));
/// <summary>
/// This method will retry the action represented by the 'action' argument, up to 'timeout'
/// This method will retry the action represented by the 'action' argument,
/// milliseconds, waiting 'delay' milliseconds after each retry and will swallow all exceptions.
/// If a given retry returns a value other than default(T), this value is returned.
/// </summary>
/// <param name="action">the action to retry</param>
/// <param name="delay">the amount of time to wait between retries in milliseconds</param>
/// <param name="timeout">the max amount of time to spend retrying in milliseconds</param>
/// <typeparam name="T">type of return value</typeparam>
/// <returns>the return value of 'action'</returns>
public static T RetryIgnoringExceptions<T>(Func<T> action, int delay, int timeout)
=> RetryIgnoringExceptions(action, TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(timeout));
public static T RetryIgnoringExceptions<T>(Func<T> action, int delay)
=> RetryIgnoringExceptions(action, TimeSpan.FromMilliseconds(delay));
/// <summary>
/// This method will retry the action represented by the 'action' argument, up to 'timeout',
/// This method will retry the action represented by the 'action' argument,
/// waiting for 'delay' time after each retry. If a given retry returns a value
/// other than default(T), this value is returned.
/// </summary>
/// <param name="action">the action to retry</param>
/// <param name="delay">the amount of time to wait between retries</param>
/// <param name="timeout">the max amount of time to spend retrying</param>
/// <typeparam name="T">type of return value</typeparam>
/// <returns>the return value of 'action'</returns>
public static T Retry<T>(Func<T> action, TimeSpan delay, TimeSpan timeout)
public static T Retry<T>(Func<T> action, TimeSpan delay)
{
var beginTime = DateTime.UtcNow;
var retval = default(T);
do
return RetryHelper(() =>
{
try
{
retval = action();
return action();
}
catch (COMException)
{
// Devenv can throw COMExceptions if it's busy when we make DTE calls.
return default(T);
}
if (!Equals(default(T), retval))
{
return retval;
}
else
{
System.Threading.Thread.Sleep(delay);
}
}
while (beginTime.Add(timeout) > DateTime.UtcNow);
return retval;
},
delay);
}
/// <summary>
/// This method will retry the action represented by the 'action' argument, up to 'timeout'
/// This method will retry the action represented by the 'action' argument,
/// milliseconds, waiting 'delay' milliseconds after each retry and will swallow all exceptions.
/// If a given retry returns a value other than default(T), this value is returned.
/// </summary>
/// <param name="action">the action to retry</param>
/// <param name="delay">the amount of time to wait between retries in milliseconds</param>
/// <param name="timeout">the max amount of time to spend retrying in milliseconds</param>
/// <typeparam name="T">type of return value</typeparam>
/// <returns>the return value of 'action'</returns>
public static T RetryIgnoringExceptions<T>(Func<T> action, TimeSpan delay, TimeSpan timeout)
public static T RetryIgnoringExceptions<T>(Func<T> action, TimeSpan delay)
{
var beginTime = DateTime.UtcNow;
var retval = default(T);
Exception e = null;
do
return RetryHelper(() =>
{
try
{
retval = action();
}
catch (Exception ex)
{
e = ex;
}
if (!Equals(default(T), retval))
{
return retval;
return action();
}
else
catch (Exception)
{
System.Threading.Thread.Sleep(delay);
return default(T);
}
},
delay);
}
while (beginTime.Add(timeout) > DateTime.UtcNow);
if (Equals(default(T), retval))
private static T RetryHelper<T>(Func<T> action, TimeSpan delay)
{
if (e == null)
while (true)
{
throw new Exception($"Function never assigned a value after {timeout.Minutes} minutes and {timeout.Seconds} seconds and no exceptions were thrown");
}
else
var retval = action();
if (!Equals(default(T), retval))
{
throw new Exception($"Function never assigned a value after {timeout.Minutes} minutes and {timeout.Seconds} seconds. Last observed excepton was:{e.Message}{e.StackTrace}");
}
return retval;
}
return retval;
System.Threading.Thread.Sleep(delay);
}
}
}
}
......@@ -20,6 +20,6 @@ public static bool WaitForLightBulbSession(ILightBulbBroker broker, Microsoft.Vi
HostWaitHelper.PumpingWait(Task.Delay(TimeSpan.FromSeconds(1)));
return broker.IsLightBulbSessionActive(view);
}, TimeSpan.FromSeconds(0), TimeSpan.MaxValue);
}, TimeSpan.FromSeconds(0));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册