Visual Studio loading test to simulate many users in Data Driven mode?

I am trying to download a test web service.

I have a simple method that takes 2 parameters that are sent to a web service and returns a response, and I created Unit Test from this method.

Since I want to test various different inputs in order to test the service effectively, I am setting up CSV with ~ 1000 lines as the data source for Unit Test.

I can run this Unit Test and it will rotate along all the lines, sequentially calling the web service with different values.

However , this is not what I need. I need each line to match a different user in a different thread, using load testing configuration to enable reflection time, build up users with step load, test mix configuration, etc.

I can achieve this by removing my data source from Unit Test values โ€‹โ€‹and hard coding .. , but this is a fundamentally wrong test:. To really test the web service, I need each user to send different values โ€‹โ€‹and get different results.

...

So, how can I connect a data source to a load test test and run this load test for each user instance of Unit Test with different values?

+4
source share
3 answers

I ended up using this answer as a guide: fooobar.com/questions/1376736 / ...

Instead of creating Unit Test from the console application method and Load Test, which is Unit Test, I created a simple ASP.NET web form that contributed data and was called a web service.

I recorded a web performance test using this new form and created a load test to run this WPTest.


  • After recording the test, I added CSV as the data source for this test.

  • 2 "Requests" were registered: initial GET and subsequent POST. Make sure you leave them both! I deleted the favicon.ico request because it was not there. (these precautions can be avoided)

  • By expanding the POST request, I changed the properties of the TextBox parameters that matched my 2 web service inputs to get their values โ€‹โ€‹from the corresponding column in the CSV.

  • I changed the DataSource Access method to "Do not move the cursor automatically" (you need to expand the DataSource into a table and edit its properties by right-clicking / F 4.)

  • Then I created a WebTestPlugin (from the linked answer), which manually moves the cursor according to the running user (int). This will correspond to the user instance that runs the load test in accordance with the step plan. Once you create this class, create a project and add it to your web performance test.


public class webtestplugin : WebTestPlugin { public override void PreWebTest(object sender, PreWebTestEventArgs e) { base.PreWebTest(sender, e); e.WebTest.MoveDataTableCursor("DataSource1", "addresses#csv", e.WebTest.Context.WebTestUserId); } } 
+4
source

To answer your question, I am sure that this cannot be done out of the box of MSTest and NUnit ( this approach will not be this scenario).


But, IMHO, just not there ... In my experience, simulating ~ 1000 users from one machine will lead to bad results, because in the test all kinds of client restrictions will be encountered - problems of the thread pool, outgoing and problems with incoming traffic, etc. . I am not saying that this cannot be overcome, but he twisted enough to consider a different approach.

In fact, I do not recommend using load testing tools (in this case there are a lot of them), since it is enough to simply write a small tool and skip configuration problems and learning curves of the 3rd party.

What I recommend is writing your own tool and running it from individual machines. It does not need to be run using the testing framework (I cannot force myself to call it unit test, because it is not), the console application will do the trick. Here is the code to get you started:

 private ConcurrentBag<string> logs = new ConcurrentBag<string>(); public void GetLoad(int numberOfUsers, List<string> myParams) { var users = new string[numberOfUsers]; for (int i = 0; i < numberOfUsers; i++) { users[i] = string.Format("LoadTest{0}", i + 1); } var userThreads = new List<Thread>(); for (int i = 0; i < numberOfUsers; i++) { int index = i; userThreads.Add(new Thread(()=> CallWebService(users[index], myParams[index]))); } Parallel.ForEach(userThreads, thread=>thread.Start()); foreach (var userThread in userThreads) { userThread.Join(); } var outputFilename = string.Format("LoadTest.{0}Users.txt", numberOfUsers); File.AppendAllLines(outputFilename, logs); } 
+2
source

The figure shows where to make changes.

enter image description here

0
source

Source: https://habr.com/ru/post/1437604/


All Articles