Thanks for responding 'sebb'. For completeness: in my case, does that mean that the While controller completely prevents the PreProc. from being run, or just that it's run after the While controller and is therefore ineffectual for loop control? Cheers. ----- Original Message -----
From: "sebb" <[email protected]> To: "JMeter Users List" <[email protected]> Sent: Tuesday, 29 July, 2014 2:35:29 PM Subject: Re: BeanShell PreProcessor doesn't seem to work as I expect A Pre-Processor is only run just before a sampler. On 29 July 2014 04:06, Nigel Donaldson <[email protected]> wrote: > I have the following arrangement in a Test Plan: > > Thread Group > - Module Controller > > where the module references/includes the following: > > Test Fragment > - Transaction Controller > -- BeanShell Sampler -or- BeanShell PreProcessor > -- While Controller > --- HTTP Request > --- BeanShell PostProcessor > ... > > The BeanShell Sampler (or PreProcessor) simply initialises a number of > variables: > > vars.put("MaxNofAttempts", String.valueOf(bsh.args[0])); > vars.put("AttemptCount", "0"); vars.put("RC", "0"); > > The While test is: > > ${__javaScript("${RC}"!="200" && "${RC}"!="500" && > "${MaxNofAttempts}">"${AttemptCount}")} > > The PostProcessor checks the response-code of the HTTP request (which may be > a meaningful 4xx, leading to an increment of the key variable): > > vars.put("RC", ctx.getPreviousResult().getResponseCode()); > if (vars.get("RC").substring(0, 1).equals("4")) { vars.put("AttemptCount", > String.valueOf( Integer.parseInt(vars.get("AttemptCount"))+1 )); } > > > If I use a BeanShell Sampler the arrangement works as expected (ie. up to a > fixed number of retries upon 4xx response-codes, or flow-through upon 200 or > 500). > > However, if I use a BeanShell PreProcessor instead, the While test fails > (leading to an infinite loop) because the value of the 'AttemptCount' > variable appears unchanged. > > I don't understand this. I'd appreciate an explanation and/or suggestions. > (For what it's worth, I originally had JSR223 elements, with the same > result). > > Cheers, > Nige > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
