Skip to content

Commit 56b7d0e

Browse files
authored
Fix BigInteger outerloop test (dotnet#111841)
* Fix BigInteger outerloop test This has presumably been failing since capping BigInteger to a maximum length * Update src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs * 2MB * convert ToString_ValidLargeFormat to inner loop
1 parent 84f4c2a commit 56b7d0e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,22 +521,23 @@ public static void ToString_InvalidFormat_ThrowsFormatException()
521521
Assert.Throws<FormatException>(() => b.ToString("G000001000000000"));
522522
}
523523

524-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))] // Requires a lot of memory
525-
[OuterLoop("Takes a long time, allocates a lot of memory")]
526-
[SkipOnMono("Frequently throws OOM on Mono")]
524+
[Fact]
527525
public static void ToString_ValidLargeFormat()
528526
{
529527
BigInteger b = new BigInteger(123456789000m);
530528

531529
// Format precision limit is 999_999_999 (9 digits). Anything larger should throw.
530+
// We use TryFormat rather than ToString to avoid excessive memory usage.
532531

533-
// Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format
534-
b.ToString("E999999999"); // Should not throw
535-
b.ToString("E00000999999999"); // Should not throw
532+
// Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format.
533+
// Currently disabled since these would still allocate a 2GB buffer before
534+
// returning, leading to OOM in CI.
535+
//Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "E999999999")); // Should not throw
536+
//Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "E00000999999999")); // Should not throw
536537

537538
// Check ParseFormatSpecifier in Number.BigInteger.cs with `G` format
538-
b.ToString("G999999999"); // Should not throw
539-
b.ToString("G00000999999999"); // Should not throw
539+
Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "G999999999")); // Should not throw
540+
Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "G00000999999999")); // Should not throw
540541
}
541542

542543
private static void RunSimpleProviderToStringTests(Random random, string format, NumberFormatInfo provider, int precision, StringFormatter formatter)

src/libraries/System.Runtime.Numerics/tests/BigInteger/GetBitLengthTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public static void RunGetBitLengthTests()
4444
public static void RunGetBitLengthTestsLarge()
4545
{
4646
// Very large cases
47-
VerifyGetBitLength(BigInteger.One << 32 << int.MaxValue, int.MaxValue + 32L + 1, 1);
48-
VerifyGetBitLength(BigInteger.One << 64 << int.MaxValue, int.MaxValue + 64L + 1, 1);
47+
// Values which are large but beneath the upper bound of
48+
// (2^31) - 1 bits and which should not cause OOM in CI.
49+
VerifyGetBitLength(BigInteger.One << 32 << (1 << 24), (1 << 24) + 32L + 1, 1);
50+
VerifyGetBitLength(BigInteger.One << 64 << (1 << 24), (1 << 24) + 64L + 1, 1);
4951
}
5052

5153
private static void VerifyLoopGetBitLength(Random random, bool isSmall)

0 commit comments

Comments
 (0)