Fix bug in iterator test, modify attempt count, make more robust (#61242)
authorKatelyn Gadd <kg@luminance.org>
Fri, 5 Nov 2021 10:55:12 +0000 (03:55 -0700)
committerGitHub <noreply@github.com>
Fri, 5 Nov 2021 10:55:12 +0000 (11:55 +0100)
src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs

index edbb866..7158c38 100644 (file)
@@ -186,18 +186,31 @@ namespace System.Runtime.InteropServices.JavaScript.Tests
                     return rangeIterator;
                 ");
 
-            for (int attempt = 0; attempt < 100_000; attempt++)
+            const int count = 500;
+            for (int attempt = 0; attempt < 100; attempt++)
             {
+                int index = 0;
                 try
                 {
-                    using (var entriesIterator = (JSObject)makeRangeIterator.Call(null, 0, 500))
-                    {
-                        var cnt = entriesIterator.ToEnumerable().Count();
+                    var entriesIterator = (JSObject)makeRangeIterator.Call(null, 0, count, 1);
+                    Assert.NotNull(entriesIterator);
+                    using (entriesIterator) {
+                        var enumerable = entriesIterator.ToEnumerable();
+                        var enumerator = enumerable.GetEnumerator();
+                        Assert.NotNull(enumerator);
+
+                        using (enumerator) {
+                            while (enumerator.MoveNext()) {
+                                Assert.NotNull(enumerator.Current);
+                                index++;
+                            }
+                        }
                     }
+                    Assert.Equal(count, index);
                 }
                 catch (Exception ex)
                 {
-                    throw new Exception(ex.Message + " At attempt=" + attempt, ex);
+                    throw new Exception($"At attempt={attempt}, index={index}: {ex.Message}", ex);
                 }
             }
         }