Adjustable Think Time For Dynamic Polling Requests

This post has been republished via RSS; it originally appeared at: TestingSpot Blog articles.

First published on MSDN on Feb 22, 2018

Authored by Christopher Witte

So, you just recorded your script and see a polling request from the browser and if that isn’t painful enough you also notice that the time between requests changes. Never fear, we have a plug-in for that.

First, let’s deal with the pesky polling request by using the built-in loops and extraction rules. This is going to be different depending on your developer’s implementation of the polling, and you should observe the traces you have captured to determine a good way to know when all the data has been returned from the server. In this example the response from the polling request contains a value named Status. When Status = Idle I know that all the data has been returned and I can stop polling.

Let me walk you through an example using the code provided.

We can see that there is a response variable named Status, which we know is Idle when the server is finished executing.

So First let us create an extraction rule for Status. I decided to use Regex, and you can use your favorite extraction method.

Next, we create a loop that terminates when status = Idle. In this case we used the string comparison loop.

From the request we notice there is a polling interval, so during the test in order to simulate the traffic generated we need to closely adhere to this polling interval. Let’s extract that value as well.

Next, we apply some test code that creates a request plugin to dynamically set the think time of a request, and allow it to use a context parameter.

public class ThinkTimeFromPolling:WebTestRequestPlugin
[Description("The context parameter that stores the polling value")]
public string TargetParam { get; set; }

public override void PreRequestDataBinding(object sender, PreRequestDataBindingEventArgs e)
if(e.WebTest.Context[TargetParam] != null)
double Thinktime = double.Parse(e.WebTest.Context[TargetParam].ToString());
e.Request.ThinkTime = Convert.ToInt32(Thinktime/1000);

Finally, we compile then add the plugin to the request inside the loop, setting the extracted polling interval to the think time.

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.