stabilize Copy_LargeMultiDimensionalArray test (#484)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Tue, 3 Dec 2019 20:07:58 +0000 (12:07 -0800)
committerGitHub <noreply@github.com>
Tue, 3 Dec 2019 20:07:58 +0000 (12:07 -0800)
src/libraries/System.Runtime/tests/Helpers.cs
src/libraries/System.Runtime/tests/System/ArrayTests.cs

index a092d70..76851b8 100644 (file)
@@ -6,9 +6,14 @@ using System.Collections.Generic;
 using System.Globalization;
 using System.Reflection;
 using System.Reflection.Emit;
+using Xunit;
+using Xunit.Abstractions;
 
 namespace System.Tests
 {
+    [CollectionDefinition("NoParallelTests", DisableParallelization = true)]
+    public partial class NoParallelTests { }
+
     public static class Helpers
     {
         private static Type s_refEmitType;
index 57ac706..9d0a8ef 100644 (file)
@@ -8,7 +8,9 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Reflection;
 using System.Runtime.CompilerServices;
+using Microsoft.DotNet.XUnitExtensions;
 using Xunit;
+using Xunit.Abstractions;
 
 namespace System.Tests
 {
@@ -1319,25 +1321,6 @@ namespace System.Tests
             Assert.Equal(expected, destinationArrayClone);
         }
 
-        [OuterLoop] // Allocates large array
-        [Fact]
-        public static void Copy_LargeMultiDimensionalArray()
-        {
-            // If this test is run in a 32-bit process, the large allocation will fail.
-            if (IntPtr.Size != sizeof(long))
-            {
-                return;
-            }
-
-            short[,] a = new short[2, 2_000_000_000];
-            a[0, 1] = 42;
-            Array.Copy(a, 1, a, Int32.MaxValue, 2);
-            Assert.Equal(42, a[1, Int32.MaxValue - 2_000_000_000]);
-
-            Array.Clear(a, Int32.MaxValue - 1, 3);
-            Assert.Equal(0, a[1, Int32.MaxValue - 2_000_000_000]);
-        }
-
         [Fact]
         public static void Copy_NullSourceArray_ThrowsArgumentNullException()
         {
@@ -4579,4 +4562,34 @@ namespace System.Tests
 
         public enum Int64Enum : long { }
     }
+
+    [Collection("NoParallelTests")]
+    public class DangerousArrayTests
+    {
+        [OuterLoop] // Allocates large array
+        [ConditionalFact]
+        public static void Copy_LargeMultiDimensionalArray()
+        {
+            // If this test is run in a 32-bit process, the large allocation will fail.
+            if (IntPtr.Size != sizeof(long))
+            {
+                return;
+            }
+
+            try
+            {
+                short[,] a = new short[2, 2_000_000_000];
+                a[0, 1] = 42;
+                Array.Copy(a, 1, a, Int32.MaxValue, 2);
+                Assert.Equal(42, a[1, Int32.MaxValue - 2_000_000_000]);
+
+                Array.Clear(a, Int32.MaxValue - 1, 3);
+                Assert.Equal(0, a[1, Int32.MaxValue - 2_000_000_000]);
+            }
+            catch (OutOfMemoryException)
+            {
+                throw new SkipTestException("Unable to allocate enough memory");
+            }
+        }
+    }
 }