Hi,
I wrote a simple load test plugin and used LoadTest.ThresholdExceeded.
I set a threshold rule for process time in the local machine (testing
machine). In the handler, I specified that when an ThresholdExceeded
event occured, a message box wouldl pop up and the load test would be
aborted. But it seems to me the handler was not working well. Although
I saw a lot of threshold violations in the in the test result wizard, I
never got any message specified in the handler. I don't know why.
Can anyone help me
Thank you very much.
Ran Mouri
My code is below:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.LoadTesting;
using System.Windows.Forms;
using NormalLoadTest;
namespace LoadTestPlugin
{
public class LoadTestPlugin : ILoadTestPlugin
{
LoadTest v_loadTest = null;
int v_count = 0;
string v_connectionString = "Data
Source=ATP-ESE-WSA3;Initial Catalog=Stockonline;Integrated
Security=True";
public void Initialize(LoadTest p_loadTest)
{
v_loadTest = p_loadTest;
//Specify event handler for this load test
v_loadTest.ThresholdExceeded += new
EventHandler<ThresholdExceededEventArgs>(v_loadTest_ThresholdExceeded);
}
void v_loadTest_ThresholdExceeded(object sender, ThresholdExceededEventArgs e)
{
MessageBox.Show("Threshold: " + e.CounterValue);
v_loadTest.Abort();
}
}
}

LoadTest.ThresholdExceeded problem
ValidDisplayName
I used the local machine for this program. The strange thing is I sometimes got the right results, and sometimes, I did not get any notice for threshold. I will check it again.
Thanks
Ran Mouri
John Hind
I removed all of my current unit tests in Test Mix and created a very simple unit method (sum up values) and ran load test, the code worked. But I used that load test with the old unit tests, it did not work. Those unit tests tested some methods in a library involved I wrote myself. The library is about Stock online operations. I tested buyStock and sellStock that call some methods of other objects with database queries.Those unit tests executed normally and produced some results but I could not get any notice for threshold.
I really don't know what is going. Can you help me
I hope my question is clear enough.
Thanks
Dan Danz
Ran Mouri
Trojanfan20
I would not recommend using a MessageBox for this. I copied your code and tried it by running a load test locally. A message box was created, but it was hidden behind the Visual Studio window, so I didn't notice it for a while until I noticed it in the task bar. When I finally noticed it and clicked OK, the load test did abort (MessageBox.Show doesn't return until the box is dismissed by the user). Also, if you are running the load test on a remote agent, the message box will come up on the agent (or maybe not at all) and the user running the test from Visual Studio won't see it at all.
Instead, I would recommend that you change your threshold exceeded handler to this:
void v_loadTest_ThresholdExceeded(object sender, ThresholdExceededEventArgs e){
ApplicationException ex = new ApplicationException("Threshold: " + e.CounterValue);
v_loadTest.Abort(ex);
}
I tried this and it works. With this implementation the load test should be aborted immediately without waiting for the message box to be dismissed. The error will show up in the errors table in the load test results UI. It really should also be included in the Error Message column in the Test Results window, but due to a bug the error message there will be something like:
Test did not execute. The test/run was aborted on agent 'Agent1' due to error: 'Test Adapter on agent 'Agent1' has requested to stop the test.'.
KenHay
I tried out this code and was able to get it to work to way you wanted. The only difference is I commented out the using NormalLoadTest; line.
1) Are you running this on the local process. This is be default. Or are you running against an Agent/Controller.
2) Can you check that the plugin is set on the load test. Click on the root node of the load test and verify the Load Test Plugin property is set properly. If it is not, right click on the root node of the load test and select Set Load Test Plug In... and try setting the plugin again.
MotoJames
Please double check the following things:
1) Do you have the plug-in set on the Load Test (select the root node and look at the properties)
2) You you have a threshold rule associated with the performance counter in question
3) Is the performance counter generating a value during the load test that should trigger a threshold violation
I'm not sure what you meant by "the code worked". Did you mean that a threshold violation was triggered when you ran the new unit test under load but did not trigger when you ran the old unit test in a load test
Thanks,
Rick