diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs index f0219a252787a6..8aec40e50d4e13 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs @@ -521,22 +521,23 @@ public static void ToString_InvalidFormat_ThrowsFormatException() Assert.Throws(() => b.ToString("G000001000000000")); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))] // Requires a lot of memory - [OuterLoop("Takes a long time, allocates a lot of memory")] - [SkipOnMono("Frequently throws OOM on Mono")] + [Fact] public static void ToString_ValidLargeFormat() { BigInteger b = new BigInteger(123456789000m); // Format precision limit is 999_999_999 (9 digits). Anything larger should throw. + // We use TryFormat rather than ToString to avoid excessive memory usage. - // Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format - b.ToString("E999999999"); // Should not throw - b.ToString("E00000999999999"); // Should not throw + // Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format. + // Currently disabled since these would still allocate a 2GB buffer before + // returning, leading to OOM in CI. + //Assert.False(b.TryFormat(Span.Empty, out _, format: "E999999999")); // Should not throw + //Assert.False(b.TryFormat(Span.Empty, out _, format: "E00000999999999")); // Should not throw // Check ParseFormatSpecifier in Number.BigInteger.cs with `G` format - b.ToString("G999999999"); // Should not throw - b.ToString("G00000999999999"); // Should not throw + Assert.False(b.TryFormat(Span.Empty, out _, format: "G999999999")); // Should not throw + Assert.False(b.TryFormat(Span.Empty, out _, format: "G00000999999999")); // Should not throw } private static void RunSimpleProviderToStringTests(Random random, string format, NumberFormatInfo provider, int precision, StringFormatter formatter) diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs index ab02a31ad5b17f..f8422070565db3 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs @@ -44,8 +44,10 @@ public static void RunGetBitLengthTests() public static void RunGetBitLengthTestsLarge() { // Very large cases - VerifyGetBitLength(BigInteger.One << 32 << int.MaxValue, int.MaxValue + 32L + 1, 1); - VerifyGetBitLength(BigInteger.One << 64 << int.MaxValue, int.MaxValue + 64L + 1, 1); + // Values which are large but beneath the upper bound of + // (2^31) - 1 bits and which should not cause OOM in CI. + VerifyGetBitLength(BigInteger.One << 32 << (1 << 24), (1 << 24) + 32L + 1, 1); + VerifyGetBitLength(BigInteger.One << 64 << (1 << 24), (1 << 24) + 64L + 1, 1); } private static void VerifyLoopGetBitLength(Random random, bool isSmall)