Harden PerfCounter tests (dotnet/corefx#37658)
authorViktor Hofer <viktor.hofer@microsoft.com>
Wed, 15 May 2019 01:28:16 +0000 (03:28 +0200)
committerStephen Toub <stoub@microsoft.com>
Wed, 15 May 2019 01:28:16 +0000 (18:28 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/4361e909ff46231bd49b0736f8c4588f5e87e192

src/libraries/System.Diagnostics.PerformanceCounter/tests/Helpers.cs

index 0a9cabd..110fce1 100644 (file)
@@ -50,29 +50,14 @@ namespace System.Diagnostics.Tests
 
         public static T RetryOnAllPlatforms<T>(Func<T> func)
         {
-            T entry = default(T);
-            int retries = 20;
-            while (retries > 0)
+            // Harden the tests increasing the retry count and the timeout.
+            T result = default;
+            RetryHelper.Execute(() =>
             {
-                try
-                {
-                    entry = func();
-                    retries = -1;
-                }
-                catch (InvalidOperationException)
-                {
-                    Thread.Sleep(100);
-                    retries--;
-                }
-                catch (ArgumentException)
-                {
-                    Thread.Sleep(100);
-                    retries--;
-                }
-            }
+                result = func();
+            }, maxAttempts: 10, (iteration) => iteration * 300);
 
-            Assert.NotEqual(0, retries);
-            return entry;
+            return result;
         }
     }
 }