问题
I have JSR233 listener under HTTP Request, it stores all the response time values, creates array and then sort the array to find 90% line and then marks the last transaction/Request Pass or Fail if the final 90% Line threshold is reached. Everything works perfect in GUI but I am running this test in Gitlab CI using Docker Image and it looks like this JSR233 script get ignored 8 out of 10 times but 2 times it works fine there as well. Really confused It behaves weird in windows console JMeter non-gui too, it gets ignored may be
String requests = props.get("requests");
long requestsSum = 0;
if (requests != null) {
requestsSum = Long.parseLong(props.get("requests"));
}
long thisRequest = sampleResult.getTime();
requestsSum++;
props.put("requests", String.valueOf(requestsSum));
props.put("rt"+String.valueOf(requestsSum), String.valueOf(thisRequest));
if ( requestsSum > 4 ) {
ArrayList strList = new ArrayList();
for (int i=1;i<6; i++){
strList.add(Integer.parseInt(props.get("rt"+String.valueOf(i))));
}
vars.putObject("ArrayListBeforeSorting",strList);
Collections.sort(strList);
vars.putObject("ArrayListAfterSorting",strList);
String HID = vars.get("ArrayListAfterSorting"); String[] words = HID.split(",");
log.info("ninetypercent line is: " + words[3]);
vars.put("NPL" , words[3]);
int ninetypercentline = Integer.parseInt(words[3].trim());
if ( ninetypercentline > 100 ) {
sampleResult.setSuccessful(false);
sampleResult.setResponseMessage("ninety percent line is reached");
}
}
回答1:
JMeter doesn't "ignore" anything, you can double check it youself by:
Putting __counter() function into the "Parameters" field of your JSR223 Listener like:
${__counter(FALSE,)}
Adding this line as the first line of your script:
println('Executing listener #' + ((Parameters as int) -1))
You should see the following output in the stdout:
Executing listener #1
Executing listener #2
Executing listener #3
Executing listener #4
Executing listener #5
Executing listener #6
Executing listener #7
Executing listener #8
Executing listener #9
Executing listener #10
which means that the listener has been executed 10 times (the actual order may be different depending on your ramp-up settings)
With regards to your code itself, be aware that if you have > 1 virtual user your so called "code" will either fail or produce invalid results due to the race condition as these requests
, and rt*
values are global
Properties are not the same as variables. Variables are local to a thread; properties are common to all threads
来源:https://stackoverflow.com/questions/61461468/i-have-jsr233-listener-which-seems-to-be-ignored-in-jmeter-non-gui-mode