I do request retransmission until I get the expected response.
I need to send one request and from the response, need to check the value of this one variable and if the response is not matching, then I need to send the same request again until I get the expected response.
On this case, I need to stop to request re-sending after some time, say two minutes. After two minutes, if I didn't get the proper response, then the request needs to stop being re-transmitted.
Please let me know how simulate this (loop controller + timer case)
I would rather go for While Controller instead of the Loop Controller as in case of the While Controller you will be able to exit the loop earlier than 2 minutes in case if the response does match the expected value.
For instance the following function specified in the While Controller:
${__javaScript("${yourVar}"!="foo",)}
will trigger While Controller's children to run until ${yourVar} value won't become foo, something like:
__javaScript() function is required in order to evaluate and compare variables as While Controller (unlike If Controller) doesn't treat the input as JavaScript so you need to pass the function explicitly.
Duration of the retrying logic can be set using Runtime Controller which basically defines for how long its children are allowed to run.
Related
Is there a way for all Receive samplers to ignore specific responses in JMeter and wait for the one that we are interested?
To be more precise, we have created a jmx file that contains a large flow like a user would create on the browser. Each request sent is followed by a response, so we use a request handler followed by the corresponding receive handler for each call. And everything seems to work fine.
But there are cases that another kind of response may arrive, which is not the one we expect in our flow, but it is triggered by another independent mechanism. You can think of it like notifications sent to the user that is doing the flow and are independent of the flow itself, but theu are received in the channel (for us inside the websocket connection).
So we are trying to find a way to ignore a specific set of responses that may come while we are running the tests.
We firstly tried to add a While Controller in each receive sampler that checks if the content is of the desired type and if not loops again. But this solution has 3 disadvantages :
we have to add the sampler for the specific receive twice - one before the while element and one inside the element because we have to first extract the received data and while does not execute its contents before doing the while condition check
we have so many pairs of send-receive in our jmeter test script , that we have to add so many while controllers inside the script
since the received message may not be of the type we expect but another one that we want to ignore, then we cannot add a Response Assertion because it will fail if the notification arrives, so we have to verify the content indirect -> in the condition of the while loop
We use apache-jmeter-5.3.
So we are wondering if we could do another kind of configuration in order to avoid all these while loops.
It may be irrelevant to the solution, but we use websocket through "WebSocket Samplers by Peter Doornbosch".
Thanks
You don't have to, just amend your While Controller's condition to accept undefined variable as well
Sounds like a potential use case for using Module Controller to avoid code duplication
If you're getting the response you don't expect you can change the response body using JSR223 PostProcessor to the one you expect, example code
if (!prev.getResponseDataAsString().contains('foo')) {
prev.setResponseData('foo', 'UTF-8')
}
In light words the problem could be stated as "I am setting an environment variable in one transformation t1.ktr and using the variable in another transformation t2.ktr. I want to update the variable every 15 mins without actually stopping the t2.ktr i.e. during the execution of t2.ktr . How can I achieve that ?
To give you an overview :
I am making rest api call using HTTP POST step in my transformation (multi-threaded). To make this rest api call I need to pass a certain Token which gets expired in every 15 mins. I am getting this token via another API call. So in one transformation lets say token.ktr I am getting the token and storing it in environment variable TOKEN via Set Variable step and in next transformation lets call it rest.ktr I am getting this variable via Get Variable step and using it in HTTP POST call.
For 15 min I get proper responses, but after that I get error responses since token gets expired.
Let me know if further clarification is needed.
I've had a similar case that i produced a sequence of KTRs in a Job with Evaluations.
I achieved this with a Job and 2 KTRs
DISCLAIMER - For my case, i have to make several HTTP GET's, not just a single long one, so i can easily loop from one GET to another and check the Expiration of the Token bettween HTTP GETs, this is how i achieved it.
Step 1:
Start your KTR that has the Auth API Call. In this KTR you'll also use a formula step, creating a DateTime row using the NOW() function, this will get the timestamp of when you called the Authorization. This KTR will end by setting the Auth and this timestamp as variables in the Parent job.
KTR1 - Example
Step 2:
In the Job you will call this KTR first, and right after it, you'll use a Set Variables step, i named this variable Expiration, and here you'll set it to OK, signaling Token not expired. Next you'll call the KTR that makes the HTTP GET, using the Token. The result of this KTR will be Success (not expired token, success on HTTP GET, moves on), or Fail (Token expired, set Expiration to "Expired").
JOB Example
Step 3:
After the HTTP GET you need to check to result, whether or not it succeeded, or if the token expired mid way, so you would need to renew token and continue the loop, or end the loop if no more HTTP GETs are needed.
Again, this is for a very especific use case, and i'm sure other people can do better, but, this is my take on the issue, it works for me.
Right now, I have a Simple Controller set up to send a HTTP Request, and am extracting the request ID number from the response I get. This is working correctly. However, I want to send 3 such requests, and extract the request ID number from each, and may want to do even more in the future. I'm thinking the best way to set this up would be a loop controller, but I'm not sure how to extend my regex extractor that works for 1 HTTP request to work for multiple HTTP requests. The request ID number will be different each time, so I have to have a different variable for each, but I'm not sure how to make that happen. I was also looking at the ForEach loop, but I don't have any variables I am using as input, so I'm not sure that is the right choice for what I'm looking to do.
I have a page which fires Ajax requests for validations at server side. I need to perform an action when all the ajax requests have finished loading or are completed.
For this, I am using Ext.Ajax.isLoading() in a recursive function in following way:
function chechValid(){
if(Ext.Ajax.isLoading()){
checkValid();
}else{
//Code for Action 1
}
}//EOF
checkValid();
//Code for Action 2
The problem is that when I do this, browsers give the following errors:
Mozill FF - too much recursions
IE - Stack overflow at line:18134
If this recursion is a heavy thing for the browsers, then how to perform a task when all the Ajax requests have finished loading?
Using delay is not what I want as, if delay is used then browser begins executing the other code (like 'Code for Action 2' as shared above) which is not what is expected.
The main aim is that the browser shouldn't execute anything unless all the Ajax requests are complete and once completed then it should perform a particular action.
Any suggestions/help on this one?
Thanks in Advance.
PS: Using ExtJs 4.0.7
(Updated)More Detail about the actual situation:-
Here is brief description of the situtaion being faced - There is a form, in which I need to perform server side validations on various fields. I am doing so by firing an ajax request on blur event. Depending upon the server response of validation Ajax fired on blur, fields are marked invalid and form submission is not allowed. (Avoiding 'change' event as that causes alot of overhead on server due to high number of Ajas requests and also leads to fluctuating effects on a field when response from various such Ajax requests are received).
Things are working fine except in one case - when user modifies the value of a field and instead of 'tab'bing out from the field she directly clicks at the save button. In such a case, though, the blur event gets fired but the processing of 'Save' doesn't wait for Ajax Validation response and submits the form. Thus, I somehow need to check if Ajax requests have finihed loading and the process the saving of form. requestComplete would unfortunately not serve the purpose here. And if try using the recursion, then of course, the browser is hung due to high usage of resources. Same case occurs if I try using a pause script work around ( as shared here - Javascript Sleep).
Any possible workaround for this one?
TIA
Your method will lead to infinite recursion.
A better way is to register a callback function in Ext.Ajax.requestcomplete, something like this (not tested):
Ext.Ajax.on('requestcomplete', function(conn, response, options) {
if (!Ext.Ajax.isLoading()) {
//your action...
}
}
};
Unless I am misunderstanding the issue couldn't you create a couple of globals. I know globals are bad, but in this case it will save you quite a bit of headache. One global would be "formReady" and initially set it to false, the other would be "ajaxActive" and set to false. You would also add an onSubmit method that would validate that "formReady" was true and if not alert the user that validation was occurring (or you could set a timeout for form submission again and have a second validation that checks to see if "ajaxActive" is true). When the AJAX call is made it would set the variable "ajaxActive" to true and once complete would set formReady to true. You could also potentially resubmit the form automatically if the response from the AJAX was that the form was good.
Ext.Ajax.request() returns a transaction object when you call it, which is unique and allows you to recognise and abort specific Ajax requests.
By just calling Ext.Ajax.isLoading() without a specified transaction object, it defaults to the last request, which is why you have to call it recursively at the moment.
If it were me, I'd create an array of these transaction objects as you fire them off, and pass each of those in as optional parameters to the Ext.Ajax.isLoading() function to check if a particular request has finished. If it has, you can remove that transaction object from the array, and only progress with the save when your array is empty.
This would get round your recursion problem, since you've always got a finite number of requests that you're waiting on.
if (Object.keys(Ext.Ajax.requests).length === 0) console.log("No active requests");
I was wondering if there is a way how to perform actions in a function after it returning a value.
i.e there is a method which returns a string. Now after the string is returned I want the method to perform another action like checking whether a condition is met so it can send out a notification or something else. Is that somehow possible?
The thing is that I am using a framework called core plot to add some plots to my application. Unfortunately this framework does not have a didFinishAddingPlot method. So I have to manually program a mechanism which notifies me whenever the plot finished plotting. When the addPlot method is called another method is called which goes through an array of values and returns a value for a specific index to plot. My idea was to put in a "if (condition)" block to check if the index is equal to the count of my values array so I know that it is now fetching the last value. However it first needs to return the value before sending a message that it finished plotting. Otherwise the last value won't get passed.
As soon as a function hits a return statement the function stops running. You would need to perform whatever other action you want to do before you return.
So, you want to return a value from your function or method, which by definition returns control (as well as your answer) to the call site. On the face of it, it's not possible; you've returned control, so you're done.
But you could spawn a new Thread during your method execution, to (for example) perform some cleanup tasks later on.
Since you tagged the question as Cocoa, check out Apple's Threaded Programming Guide, which will teach you about NSThread, POSIX threads, and more.