Skip to content

Commit 1bccd96

Browse files
committed
fix: add [NotInParallel] to random tests to prevent race conditions
Random tests using np.random.seed() share global RNG state. When run in parallel, multiple tests can interfere with each other causing: - IndexOutOfRangeException in MT19937 (race on _pos/_key access) - Non-reproducible test results Added [NotInParallel] attribute to 27 random test classes to ensure sequential execution of tests sharing the global RNG.
1 parent e484b59 commit 1bccd96

27 files changed

Lines changed: 33 additions & 6 deletions

test/NumSharp.UnitTest/OpenBugs.Random.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace NumSharp.UnitTest
2020
/// </code>
2121
/// </summary>
2222
[OpenBugs]
23+
[NotInParallel]
2324
public class OpenBugsRandom : TestClass
2425
{
2526
// ===== CRITICAL: RNG Algorithm Mismatch =====

test/NumSharp.UnitTest/RandomSampling/np.random.dirichlet.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace NumSharp.UnitTest.RandomSampling
66
/// <summary>
77
/// Tests for np.random.dirichlet (Dirichlet distribution)
88
/// </summary>
9+
[NotInParallel]
910
public class NpRandomDirichletTests : TestClass
1011
{
1112
[Test]

test/NumSharp.UnitTest/RandomSampling/np.random.f.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace NumSharp.UnitTest.RandomSampling
66
{
7+
[NotInParallel]
78
public class NpRandomFTest : TestClass
89
{
910
[Test]

test/NumSharp.UnitTest/RandomSampling/np.random.gumbel.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace NumSharp.UnitTest.RandomSampling
66
/// <summary>
77
/// Tests for np.random.gumbel (Gumbel/extreme value type I distribution)
88
/// </summary>
9+
[NotInParallel]
910
public class NpRandomGumbelTests : TestClass
1011
{
1112
// Euler-Mascheroni constant

test/NumSharp.UnitTest/RandomSampling/np.random.hypergeometric.Test.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace NumSharp.UnitTest.RandomSampling;
99
/// Samples from hypergeometric distribution without replacement.
1010
/// Mean = nsample * ngood / (ngood + nbad)
1111
/// </summary>
12-
public class RandomHypergeometricTests : TestClass
12+
[NotInParallel]
13+
public class RandomHypergeometricTests : TestClass
1314
{
1415
[Test]
1516
public void Hypergeometric_ScalarCall_ReturnsLong()

test/NumSharp.UnitTest/RandomSampling/np.random.laplace.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace NumSharp.UnitTest.RandomSampling
66
/// <summary>
77
/// Tests for np.random.laplace (Laplace/double exponential distribution)
88
/// </summary>
9+
[NotInParallel]
910
public class NpRandomLaplaceTests : TestClass
1011
{
1112
[Test]

test/NumSharp.UnitTest/RandomSampling/np.random.logistic.Test.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace NumSharp.UnitTest.RandomSampling;
88
/// Tests for np.random.logistic following NumPy 2.4.2 behavior.
99
/// Mean = loc, Variance = scale^2 * pi^2 / 3
1010
/// </summary>
11-
public class RandomLogisticTests : TestClass
11+
[NotInParallel]
12+
public class RandomLogisticTests : TestClass
1213
{
1314
[Test]
1415
public void Logistic_DefaultParameters_ReturnsScalar()

test/NumSharp.UnitTest/RandomSampling/np.random.logseries.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace NumSharp.UnitTest.RandomSampling
1111
/// Tests for np.random.logseries (logarithmic series distribution).
1212
/// Based on NumPy 2.4.2 behavior.
1313
/// </summary>
14+
[NotInParallel]
1415
public class np_random_logseries_Tests
1516
{
1617
#region Basic Functionality

test/NumSharp.UnitTest/RandomSampling/np.random.multinomial.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
namespace NumSharp.UnitTest.RandomSampling
77
{
8+
[NotInParallel]
89
public class MultinomialTests
910
{
1011
private static readonly double[] DicePvals = { 1.0 / 6, 1.0 / 6, 1.0 / 6, 1.0 / 6, 1.0 / 6, 1.0 / 6 };

test/NumSharp.UnitTest/RandomSampling/np.random.multivariate_normal.Test.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace NumSharp.UnitTest.RandomSampling
77
/// Tests for np.random.multivariate_normal
88
/// Reference: https://numpy.org/doc/stable/reference/random/generated/numpy.random.multivariate_normal.html
99
/// </summary>
10+
[NotInParallel]
1011
public class NpRandomMultivariateNormalTests : TestClass
1112
{
1213
[Test]

0 commit comments

Comments
 (0)