Crawler-Lib Concurrency Testing Helper
The Crawler-Lib Concurrency Testing Helper allows to write unit tests with multiple threads to test the concurrency behavior of components. It is also possible to use it for client/server tests.
The Crawler-Lib Concurrency Testing Helper allows to write unit tests with multiple threads to test the concurrency behavior of components. It has synchronization mechanisms to control the workflow of the threads and to record the execution steps. It is also possible to use it for client/server tests like PNUnit, but in one test. It can be used in conjunction with any unit test framework or with simply handwritten tests.
Here is a sample:
[Test]
public void TwoCodeBlocksInParallelTest()
{
// This static method runs the provided Action delegates in parallel using threads
CTestHelper.Run(
c =>
{
Thread.Sleep(1000); // Here should be the code to provide something
CTestHelper.AddSequenceStep("Provide"); // We record a sequence step for the expectations after the test
CTestHelper.SetEvent();
},
c =>
{
CTestHelper.WaitEvent(); // We wait until we can consume what is provided
CTestHelper.AddSequenceStep("Consume"); // We record a sequence step for the expectations after the test
},
TimeSpan.FromSeconds(10)); // This is a timeout parameter, if the threads are deadlocked or take too long, the threads are terminated and a timeout exception is thrown
// After Run() completes we can analyze if the recorded sequence steps are in the correct order
Expect(CTestHelper.GetSequence(), Is.EqualTo(new[] { "Provide", "Consume" }));
}
More code samples will follow.
Download and Installation
The Crawler-Lib Concurrency Testing Helper needs the :NET Fraqmework 4.5 or higer. It is available as NuGet package.
Concurrency Testing Helper NuGet Package