From 1339f52abb60c4af73306cd3776cb969ed898762 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 25 Sep 2020 21:39:17 +0200 Subject: [PATCH] Extend RetryHelper --- .../Common/tests/TestUtilities/System/RetryHelper.cs | 9 +++++++++ .../System.Net.Sockets/tests/FunctionalTests/Connect.cs | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/RetryHelper.cs b/src/libraries/Common/tests/TestUtilities/System/RetryHelper.cs index cd5221e2b41ed2..6099a9b2782866 100644 --- a/src/libraries/Common/tests/TestUtilities/System/RetryHelper.cs +++ b/src/libraries/Common/tests/TestUtilities/System/RetryHelper.cs @@ -7,6 +7,11 @@ namespace System { + public class StopRetryingException : Exception + { + public StopRetryingException(string message) : base(message) { } + } + public static partial class RetryHelper { private static readonly Func s_defaultBackoffFunc = i => Math.Min(i * 100, 60_000); @@ -36,6 +41,10 @@ public static void Execute(Action test, int maxAttempts = 5, Func back test(); return; } + catch (StopRetryingException) + { + throw; + } catch (Exception e) { exceptions.Add(e); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs index 08ecf15f3b925b..a04e368f20d421 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs @@ -140,7 +140,10 @@ await RetryHelper.ExecuteAsync(async () => var cts = new CancellationTokenSource(); Task timeoutTask = Task.Delay(30000, cts.Token); - Assert.NotSame(timeoutTask, await Task.WhenAny(disposeTask, connectTask, timeoutTask)); + if (await Task.WhenAny(disposeTask, connectTask, timeoutTask) == timeoutTask) + { + throw new StopRetryingException("The connect operation timed out."); + } cts.Cancel(); await disposeTask;