Introduction Concurrency Tester is a Visual Studio extension. It executes NUnit tests concurrently thereby simulating multi-user scenario. It is targeted against the integration tests written using NUnit. User can select the number of concurrent users and run all tests those many times in parallel. The needPerformance/stress tests are performed after development (coding) is completed. As part of development, a developer writes unit and integration tests, runs them and after successful run, declares “dev. complete”. All these tests (especially integration tests) are executed sequentially. There are scenarios listed below which are never tested because of thissequential nature of execution.
A simple case studyConsider following case study to understand how concurrency tester can help in identifying bugs in multi-user scenario. Let’s say we have got following fictitious business function.
C# Edit|Remove csharp[TestFixture] public class BusinessLayerIntegrationTest { [Test] public void WhenMoneyIsTransferredExpectNoExceptionIsThrown() { // Arrange var topSecretBusinessFunction = new TopSecretBusinessFunction(); // Act TestDelegate td = () => topSecretBusinessFunction.TransferMoney(5); // Assert Assert.DoesNotThrow(td); } } [TestFixture] public class BusinessLayerIntegrationTest { [Test] public void WhenMoneyIsTransferredExpectNoExceptionIsThrown() { // Arrange var topSecretBusinessFunction = new TopSecretBusinessFunction(); // Act TestDelegate td = () => topSecretBusinessFunction.TransferMoney(5); // Assert Assert.DoesNotThrow(td); } } Test is pretty simple. It just invokes the function and checks if there is no exception thrown.
When executed sequentially (i.e. in a single user environment), no matter however times, this test will always pass.
However, there is a subtle bug in the business function. That will only surface in multi-user environment (Refer tothis link to understand what the bug is). When you run the concurrency tester on the integration test project, the test case in executed in multi-user environment and the bug is caught as shown below. PrerequisitesConcurrency tool needs following prerequisites in order to run.
How to installOpen Visual Studio 2012/15. Go to “Tools à Extensions and Updates…” menu. In the new window presented, click “OnlineàVisual Studio Gallery” menu on the left hand side. Type in “concurrency tester” in the search box on the right hand side pane. The search results, “Concurrency Tester” will be shown in the middle pane. Click “Download” to start installation. Accept the license terms and click “Install” button. You may need to restart Visual Studio after installation. This is 1 time restart only. How to run concurrency testerOnce you have installed the “concurrency Tester” extension. Open the target Visual Studio solution. Select the “Integration Test Project” as shown below. Right click on the “Integration Test Project”, you will see the “Enter Concurrent Users” menu. Enter the value suitable in your scenario. Typical value should be close to no. of concurrent users allowed by database. This is 2000 in case of SQL Server. Below, I am selecting a 10 user environment. After entering this value, hit “ENTER”.
The results of running concurrent tests are shown in “Output” window. If this window is not already visible, go to “ViewàOutput” menu of Visual Studio.
Select “Concurrency Tester” from available choices. Read through the results in pane below. How it worksWorking of Concurrency Tester involves following main steps.
This involves selecting integration project and using context (or right click) menu. 2. Finding the output assembly. This process involves locating output assembly (DLL) from selected project.
This step involves using reflection to extract test methods.
Tasks here are the C# Tasks. Add all test cases to this list. Process is repeated for the number of users as selected for running tests.
This step involves starting all the tasks in tasks list using Task Parallel library.
|