From c835dc22b16e0710853e01045b4da5f335991c79 Mon Sep 17 00:00:00 2001 From: Akhil Indurti Date: Thu, 2 Jun 2022 15:25:35 -0700 Subject: [PATCH] fix InstanceDataCollectionCollection_CopyTo by retrying on 0 values (#70119) * fix InstanceDataCollectionCollection_CopyTo by retrying on 0 values Previously, when pcc.ReadCategory() returned 0 values, we did not retry, which broke the test that asserted its length > 0. This time, we retry when there are 0 values, by triggering the RetryHelper's exception handler. Fixes #68291 * add ZeroDataException * Revert "add ZeroDataException" This reverts commit 43ba3adf8e5e2967b60309cd2527cdac41076732. * throw xUnitException instead of making a custom one * no need for if statement --- .../tests/InstanceDataTests.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/tests/InstanceDataTests.cs b/src/libraries/System.Diagnostics.PerformanceCounter/tests/InstanceDataTests.cs index 7ff34aaafb263..0fe20de04e275 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/tests/InstanceDataTests.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/tests/InstanceDataTests.cs @@ -124,8 +124,13 @@ public static void InstanceDataCollectionCollection_CopyTo() public static InstanceDataCollectionCollection GetInstanceDataCollectionCollection() { - PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); - return Helpers.RetryOnAllPlatforms(() => pcc.ReadCategory()); + PerformanceCounterCategory pcc = Helpers.RetryOnAllPlatforms(() => new PerformanceCounterCategory("Processor")); + return Helpers.RetryOnAllPlatforms(() => + { + var idcc = pcc.ReadCategory(); + Assert.InRange(idcc.Values.Count, 1, int.MaxValue); + return idcc; + }); } public static InstanceDataCollection GetInstanceDataCollection()