JMeter JSR223 Postprocessor not updating User Parameter

2.2k views Asked by At

I have an HTTP sampler that yields a JSOn string. I parse the JSon fragment using groovy JSonSlurper to update the UserParameter pollOver:

import groovy.json.JsonSlurper

def jsonSlurper = new JsonSlurper()
def response = jsonSlurper.parseText(prev.getResponseDataAsString())
def isError = response.response.isError
def error = isError ? "true":"false"
def data = response.response.data
def pollOver = data?.trim() || isError
log.info("response = " + response)
log.info("isError = " + isError)
log.info("error = " + error)
log.info("data = " + data)
log.info("pollOver = " + pollOver)
vars.put("pollOver", pollOver ? "true":"false")
vars.put("data", data)
vars.put("error", error)

Unfortunately the User Parameter pollOver is never updated, although the log from groovy postprocessor show that it has the right value:

2017-09-13 13:03:54,296 INFO o.a.j.e.JSR223PostProcessor: response = [response:[version:1505333033161, data:138bdb6e-f0e9-48c0-8dd6-5bb14154d816, startTime:1505333033161, endTime:1505333033264, My Service, isError:false, operationIdList:[2ca8719c-152c-4baa-8cfc-8ec1022cdc09], progress: created successfully, rootId:570ef302-89a2-4bc1-bd1a-4d06fba306a0, id:570ef302-89a2-4bc1-bd1a-4d06fba306a0], version:1.0]
2017-09-13 13:03:54,296 INFO o.a.j.e.JSR223PostProcessor: isError = false
2017-09-13 13:03:54,296 INFO o.a.j.e.JSR223PostProcessor: error = false
2017-09-13 13:03:54,296 INFO o.a.j.e.JSR223PostProcessor: data = 138bdb6e-f0e9-48c0-8dd6-5bb14154d816
2017-09-13 13:03:54,296 INFO o.a.j.e.JSR223PostProcessor: pollOver = true

If I define pollOver as a User Defined Variable, it works fine. Of course, I need X to be distinct for distinct threads and hence prefer to use User Parameters as opposed to UDV.

Is there a gotcha here that I am missing? Can I not update User Parameter using vars.put(...) in a JSR223 groovy postprocessor?

Here is the While Controller whose termination is determined by UDV "pollOver" (pollOver is defined in UDV section "Create Site Parameters"): [While Controller depending on UDV][3]

Here is the postprocessor that updates UDV pollOver to make the controller terminate: [enter image description here][4]

Thanx,

R

1

There are 1 answers

3
UBIK LOAD PACK On BEST ANSWER

User Parameters is a Pre-Processor that runs before the samplers that are in its scope. As you don't provide a screenshot of your Test Plan I cannot tell what sampler it impacts, but most probably it runs before your sampler and erases the value that your stores in Variables.

For your use case, define User Parameters as a child of first sampler in Thread Group so that its scope does not erase the value computed by JSR223 PostProcessor

See:

From your comment, it seems my answer is ok, to fix it, add before while controller a Test Action with :

  • Pause mode and sleep to 0

Move inside it the User Parameter element so that it only runs once to initialize pollOver.

I just use a Test Action with Pause = 0 to avoid generating a useless SampleResult. I could have used a Debug Sampler also.

The main problem you had, as I explained is that your User Parameter scope was too large so it applied to all requests overwriting the value that your Post Processor updated.