I want to post some bulk messages. System takes some time to process them, so i do not want to proceed for 2nd iteration. My setup is something like this
While controller->jdbc request->beanshell postprocessor
In While controller, condition is ${__java script("${check_1}" != "0")}
check is the variable name as part of database sampler which checks whether all the messages are processed. Its a count, if it is 0 we have to stop looping.
As part of Bean Shell Post Processor, i have added a condition to wait if count is not equal to 0.
if(${check_1} != 0) {
out("check Count not zero, waiting for 5 sec " + ${check_1});
Thread.sleep(5000);
}else
out("check Count is zero " + ${check_1});
Whats happening is, the result is something like this
If the check_1 is > 0 , it waits for 5 sec and as soon as it is 0, it runs into infinite loop by executing the sampler multiple times
Is there something wrong with the condition. Please suggest if you have any other solution.
The correct way to use __javaScript() function and define condition is:
${__javaScript(${check_1} != 0,)}
The correct way of accessing JMeter Variables from Beanshell is:
if(vars.get("check_1").equals("0"))
Hope this helps.
Related
I want to reset my counter at end of the each iteration of the loop. I implemented solution in my script like in the page
Jmeter - Loop counter in while loop not resetting on exit
but given solution is not working for me . I am using apache jmeter 5.1.1 version I added below code in JSR223 sampler out side the while controller within transaction controller
def counter=vars.get("counter"); ${__groovy(vars.put('counter'\, '2'),)}
Counter
Counter value is resetting but updated counter value not carrying to second iteration
logs: 2019-10-24 14:53:53,281 INFO o.a.j.p.j.s.J.JSR223 Sampler: counter value-----2
Placed JSR223 Sampler outside while controller/trasaction controller/loop controller.. In all the ways it is giving same response like below
I need result as
xrequest-1
xrequest-2
xrequest-3
xrequest-4
xrequest-5
xrequest-6
xrequest-7
xrequest-8 . . .
yrequest-1
yrequest-2
yrequest-3
yrequest-4
yrequest-5
yrequest-6 . . .
Please help me if i am missing anything.
You don't even need any Counter there.
Since JMeter 5.0 While Controller exposes a special JMeter Variable which looks like:
${__jm__While Controller__idx}
where While Controller needs to match the While Controller label.
So if you need to count iterations - you can just refer this variable. It's zero-based, to wit the value will be 0 at the first iteration, if you need the iteration number to start with 1 - go for __intSum() function like:
${__intSum(${__jm__While Controller__idx},1,)}
Demo:
I have a situation like this:
Test Plan
Thread Group 1
var A = 1 ( User parameters)
HTTP request 1
HTTP request 2
Thread Group 2
var A = 2 ( User parameters)
HTTP request 3
HTTP request 4
I know that I can use "Run Thread Groups consecutively" to make these 2 thread run parallel. However, the problem is, because they are running parallel, sometimes var A=2 got recognized in Thread Group 1, and thus make the test case fail. What I ask, is there any way that I can still run these threads parallel and still make sure that the parameter values of these threads won't affect on each other? Thank you!
You can use different name for the variable so that there is no conflict.
Something like below:-
Test Plan
Thread Group 1
var A = 1 ( User parameters)
HTTP request 1
HTTP request 2
Thread Group 2
var B = 2 ( User parameters)
HTTP request 3
HTTP request 4
From the jmeter documentation:-
If you have more than one Thread Group, make sure you use different
names for different values, as UDVs are shared between Thread Groups.
Also, the variables are not available for use until after the element
has been processed, so you cannot reference variables that are defined
in the same element. You can reference variables defined in earlier
UDVs or on the Test Plan.
Hope this helps.
This is not possible as JMeter Variables scope is limited to current Thread Group only so the situation where 2nd Thread Group is reading the values from 1st Thread Group User Parameters element is either a bug in JMeter or your test fails for a different reason. For example not having a User Parameters element in 2nd Thread Group I'm not getting anything as the variable value:
I would recommend double checking expected variable A values using Debug Sampler and View Results Tree listener combination, perhaps your configuration is vague.
I am using parallel processing.
CALL FUNCTION 'ZABC' STARTING NEW TASK taskname
DESTINATION IN GROUP srv_grp PERFORMING come_back ON END OF TASK
EXPORTING
...
EXCEPTIONS
...
.
I am calling this FM inside a loop. sometimes, my records are skipped. I am not getting a desired output. Sometimes 2000 records are processed and sometimes 1000. The numbers are varying. what can be the problem ? Can you provide me some cases where records can be skipped in parallel processing ?
See the example code SAP provides: https://help.sap.com/viewer/753088fc00704d0a80e7fbd6803c8adb/7.4.16/en-US/4892082ffeb35ed2e10000000a42189d.html
Look at how they handle the resource exceptions. A resource exception means that you tried to start a new aRFC but there were no more processes available. Your program has to handle these cases. Without handling these cases the entries will be skipped. The normal handling is to just wait a little time for some of the active processes to finish, in the example program:
WAIT UNTIL rcv_jobs >= snd_jobs
UP TO 5 SECONDS.
gv_semaphore = 0.
" your internal table size.
DESCRIBE TABLE lt_itab LINES lv_lines.
LOOP AT lt_itab INTO ls_itab.
" parallel proc. -->>
CALL FUNCTION 'ZABC' STARTING NEW TASK taskname
DESTINATION IN GROUP srv_grp PERFORMING come_back ON END OF TASK
EXPORTING
...
EXCEPTIONS
...
.
" <<--
ENDLOOP.
" wait until all parallel processes have terminated. **
WAIT UNTIL gv_semaphore = lv_lines.
NOTE: You should check total parallel process count. There should be some upper limits for opened threads.
Thanks.
Currently I wait for an element to appear like this:
let populated = GREYCondition(name: "Wait for UICollectionView to populate", block: { _ in
var errorOrNil: NSError?
EarlGrey().selectElementWithMatcher(collectionViewMatcher)
.assertWithMatcher(grey_notNil(), error: &errorOrNil)
let success = (errorOrNil == nil)
return success
}).waitWithTimeout(20.0)
GREYAssertTrue(populated, reason: "Failed to populate UICollectionView in 20 seconds")
Which polls constantly for 20 seconds for collection view to populate. Is there a better, non-polling way of achieving this?
EarlGrey recommends using its synchronization for waiting for elements rather than using sleeps or conditional checks like waits wherever possible.
EarlGrey has a variable kGREYConfigKeyInteractionTimeoutDuration value in GREYConfiguration that is set to 30 seconds and states -
* Configuration that holds timeout duration (in seconds) for action and assertions. Actions or
* assertions that are not scheduled within this time will fail due to timeout.
Since you're waiting for 20 seconds for your check, you can instead simply change it to -
EarlGrey().selectElementWithMatcher(collectionViewMatcher)
.assertWithMatcher(grey_notNil(), error: &errorOrNil)
and it'll be populated without a timeout.
I like to connect Earl Grey with basic XCTest and I've come up with this simple solution to problem of waiting for elements:
app.webViews.buttons["logout()"].waitForExistence(timeout: 5)
app.webViews.buttons["logout()"].tap()
I am facing the following problem:
I have multiple HTTP Requests in my testplan.
I want every request to be repeated 4 times if they fail.
I realized that with a BeanShell Assertion, and its already working fine.
My problem is, that I don't want requests to be executed if a previous Request failed 5 times,
BUT I also dont want the thread to end.
I just want the current thread iteration to end,
so that the next iteration of the thread can start again with the 1st request (if the thread is meant to be repeated).
How do I realize that within the BeanShell Assertion?
Here is just a short extract of my code where i want the solution to have
badResponseCounter is being increased for every failed try of the request, this seems to work so far. Afterwards, the variable gets resetted.
if (badResponseCounter = 5) {
badResponseCounter = 0;
// Stop current iteration
}
I already checked the API, methods like setStopTest() or setStopThread() are given, but nothing for quitting the current iteration. I also need the preference "continue" in the thread group, as otherwise the entire test will stop after 1 single request failed.
Any ideas of how to do this?
In my opinion the easiest way is using following combination:
If Controller to check ${JMeterThread.last_sample_ok} and badResponseCounter variables
Test Action Sampler as a child of If Controller configured to "Go to next loop iteration"
Try this.
ctx.setRestartNextLoop(true);
if the thread number is 2, i tried to skip. I get the below result as i expected (it does not call b-2). It does not kill the thread either.