I have JSR233 listener which seems to be ignored in JMeter non-gui mode

依然范特西╮ 提交于 2020-04-30 08:20:32

问题


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:

  1. Putting __counter() function into the "Parameters" field of your JSR223 Listener like:

    ${__counter(FALSE,)}
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!