In a Visual Studio 2013 Web Performance test, how can I delay sending the very first request in a ".webtest" for a period of time that I specify? My web test is part of a load test. The first request of the web test should be issued after a delay period specified by a data source field. Determining when the request should be issued is simply:
delayPeriod = dataSourceValue - ( timeNow - loadTestStartTime )
Writing this delayPeriod
into the think time for a request causes the correct delay. Unfortunately, think times are applied after the response to a request is received. Hence it is easy to delay the second request of the web test until the desired time. I want to delay before the first request.
As a workaround, I have included a dummy first request to http://localhost/
and set the expected status code result to 404. The required delay is set as a think time on this request. But this add an unwanted request to localhost
.
Background: We have a log file from a web server. It gives the URL and the time for each request. We want to repeat the requests in that log file at the same rate as when they were recorded.
OK, another shot at it. Bare bones though, no error checking.
The LoadTestStartTime load test plugin puts a reference to the load test itself and the load test start time into the web test context.
The DelayWebTest web test plugin must be attached to a new web test containing one dummy request (the dummy request will not be executed). This new web test must be added to the Load Test Scenario test mix as the "Initialize Test".
The plugin reads the delay time from a context parameter, then sets the scenario's current load to 0. It then sets up a timer which calls an event handler after the properly calculated delay, which restores the load profile allowing the test to proceed. It uses locking so that only the first virtual user will execute the load profile logic while the others wait.
Seems to work. 50 users with 30 second delay:
Your solution of the dummy request to localhost is as good as it gets as far as I know. But here's an alternative shot at it.
Two parts:
(1) A load test plugin to copy the load test start time to the web test context:
(2) A web test plugin that gets its delay time from a property which can be a static value or a context parameter, and can be HH:MM:SS.SSS or integer milliseconds:
This seems to work for me.
However it uses Thread.Sleep which "...is NOT recommended for web tests is because it is a blocking API and more than one web test can share a thread, therefore it can adversely affect more than one vuser." (See Visual Studio Performance Testing Quick Reference Guide) page 187.
So this would certainly be OK for a single-user load test and maybe for small loads where virtual users don't outnumber threads*, but chances are it will screw up the results for larger loads.
(* I don't claim to know how the threading model works however)