Bug 63991 - JSR223 Preprocessor does not work on loop controller
Summary: JSR223 Preprocessor does not work on loop controller
Status: RESOLVED WORKSFORME
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: HTTP (show other bugs)
Version: 5.2.1
Hardware: Macintosh All
: P1 blocker (vote)
Target Milestone: JMETER_5.2
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-06 20:41 UTC by Jon
Modified: 2019-12-08 16:40 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jon 2019-12-06 20:41:08 UTC
I am having issue when using JSR223 preprocessor in loop controller. My use-case is that i have to process 20,000 CSV rows and where each row would be treated as request body to our backend API. In my use case JSR223 pre-processor will remove empty parameter from request and then pass the clean JSON to the API. Now the issue that i am facing is when i use JSR223 pre-processor on loop controller then first request passes and second fails giving empty request. However when i explicitly specify in thread-users let's say 100 threads (users) out of 20,0000 then each of these 100 request will pass since it is using new thread. For your reference my problem has also been posted on stack-overflow but i haven't found any solution. I am pasting the links below -


https://stackoverflow.com/questions/59060041/how-do-i-remove-empty-parameter-using-beanshell-preprocessor-in-jmeter

https://stackoverflow.com/questions/59145444/how-do-i-iterate-through-csv-in-jmeter-creating-new-thread

Also someone else is also having similar issue so i know that i am not the only one. Here is a link to that post - https://stackoverflow.com/questions/59170591/jmeter-change-the-post-request-when-json-body-contain-branket-and-slash

For your reference the JSR223 pre-processor script that i am using is - 

def request = new groovy.json.JsonSlurper().parseText(sampler.getArguments().getArgument(0).getValue())
def newRequest = evaluate(request.inspect())
request.body.each { entry ->
    if (entry.getValue().equals('')) {
        newRequest.body.remove(entry.getKey())
    }
}
sampler.getArguments().removeAllArguments()
sampler.addNonEncodedArgument('', new groovy.json.JsonBuilder(newRequest).toPrettyString(), '')


Hopefully you guys get this resolved while using loop controller or infinite loop.
sampler.setPostBodyRaw(true)
Comment 1 Philippe Mouawad 2019-12-08 16:40:23 UTC
The accepted answer (https://stackoverflow.com/questions/59060041/how-do-i-remove-empty-parameter-using-beanshell-preprocessor-in-jmeter) is wrong and is root cause of issue.

Correct answers are those ones:

- https://stackoverflow.com/a/59237491/460802
- https://stackoverflow.com/a/59237516/460802

If you're the asker, please accept the correct ones so other users are not misled.

Thank you
Comment 2 The ASF infrastructure team 2022-09-24 20:38:18 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/5208