Resolve "Bug: IndexOutOfRangeException when using multi-threaded consumers" #16
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using FastRng;
|
using FastRng;
|
||||||
using FastRng.Distributions;
|
using FastRng.Distributions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
@ -222,6 +223,32 @@ public class MultiThreadedRngTests
|
|||||||
Assert.That(lorentzContains0, Is.False, "Lorentz distribution contained 0");
|
Assert.That(lorentzContains0, Is.False, "Lorentz distribution contained 0");
|
||||||
Assert.That(lorentzContains1, Is.True, "Lorentz distribution does not contained 1");
|
Assert.That(lorentzContains1, Is.True, "Lorentz distribution does not contained 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.LONG_RUNNING)]
|
||||||
|
public void TestMultiThreadedConsumer()
|
||||||
|
{
|
||||||
|
var job1 = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
|
||||||
|
var job2 = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
|
||||||
|
var job3 = Task.Factory.StartNew(Run, TaskCreationOptions.LongRunning);
|
||||||
|
|
||||||
|
Assert.DoesNotThrowAsync(async () => await job1);
|
||||||
|
Assert.DoesNotThrowAsync(async () => await job2);
|
||||||
|
Assert.DoesNotThrowAsync(async () => await job3);
|
||||||
|
return;
|
||||||
|
|
||||||
|
float Run()
|
||||||
|
{
|
||||||
|
var sum = 0f;
|
||||||
|
var distLorentz = new CauchyLorentzX1<float>(this.rng);
|
||||||
|
for (int i = 0; i < 100_000_000; i++)
|
||||||
|
{
|
||||||
|
sum += distLorentz.NextNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Category(TestCategories.COVER)]
|
[Category(TestCategories.COVER)]
|
||||||
|
Loading…
Reference in New Issue
Block a user