Added test for stopping producers
This commit is contained in:
parent
aa7f21bbce
commit
2b0e92a91d
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FastRng.Double;
|
using FastRng.Double;
|
||||||
using FastRng.Double.Distributions;
|
using FastRng.Double.Distributions;
|
||||||
@ -261,5 +262,36 @@ namespace FastRngTests.Double
|
|||||||
|
|
||||||
Assert.That(distribution[..^1].Max() - distribution[..^1].Min(), Is.InRange(0, 6_000));
|
Assert.That(distribution[..^1].Max() - distribution[..^1].Min(), Is.InRange(0, 6_000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[Category(TestCategories.COVER)]
|
||||||
|
[Category(TestCategories.NORMAL)]
|
||||||
|
public async Task TestStoppingProducers01()
|
||||||
|
{
|
||||||
|
var rng = new MultiThreadedRng();
|
||||||
|
rng.StopProducer();
|
||||||
|
|
||||||
|
var masterToken = new CancellationTokenSource(TimeSpan.FromSeconds(16)).Token;
|
||||||
|
var wasCanceled = false;
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3));
|
||||||
|
await rng.GetUniform(tokenSource.Token);
|
||||||
|
if (tokenSource.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
wasCanceled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (masterToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.That(masterToken.IsCancellationRequested, Is.False, "Master token was used to stop test");
|
||||||
|
Assert.That(wasCanceled, Is.True, "The consumer was not canceled");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user