Reputation: 1807
I have a jMeter Test Plan with 2 http requests: submit and retrieve. First one submits some data to server. That's ok.
Then, with the second task I have to retrieve information from server. Response is json, containing taskStatus, which can be "pending" or "done". Logic is as follows: if taskStatus is "pending" I have to repeat this http request with some delay (for example, 3 seconds) automatically. However, I found no way of doing this with Http Request Sampler. Hope someone can help me. (Using Http Request Sampler is not a must)
Upvotes: 1
Views: 3342
Reputation: 2333
The long story in short (in pseudocode):
Make Submit request
Make Retreive request and extract respopnse to varialbe taskStatus
While tastSTatus != 'done'
Make Retreive request and extract respopnse to varialbe taskStatus
The long story in short (JMeter):
ReceiveRequest inside whileControllerRetreiveRequest and ReceiveRequest rigth after SubmitRequest - are equals and contain the same regular expressions inside. In theory, the only one difference is ConstantTimer in the second case.
Upvotes: 1
Reputation: 13970
It cannot be done with Http Request Sampler alone, but While Controller is to the rescue.
Structure your test like this:
Where:
Reset status (ShellBean Sampler, or any other programmable sampler) is the first item that runs that test starts. It will reset the state of test, so that it won't be confused by previous iteration. All it does is:
Submit stays as is, but Retrieve moves under a While Controller and has a post-processor attached to it now. Those 2 elements together (While controller and post-processor, make sure that Retrieve runs in loop, and that loop exists as soon as status becomes 'done'. So
While Controller looks like this:
i.e. it checks the value of the variable "Status" and only enters the loop if status is not 'done' (${__javaScript("${Status}"!="done")}
)
Finally someone needs to update ${Status}
variable after each execution of Retrieve. That is done by Extract status from response. For post-processor I cannot be more specific, since you didn't say how your result looks, but you basically need to configure it to extract status (either 'pending' or 'done' and save it in the variable ${Status}
. It may look like this (just an example, your syntax, or even type of post-processor may be different, depending on type of the response):
So here's an example of how this test would run, if it was receiving 'done' only after several iterations:
Upvotes: 2