apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.27k stars 2.09k forks source link

BSF JavaScript Preprocessor cannot access sampler variable on first interation #2180

Closed asfimport closed 15 years ago

asfimport commented 15 years ago

Thomas Johnson (Bug 46359): The BSF JavaScript Preprocessor is unable to access the Sampler variable in the first iteration, citing the following exception:

org.apache.bsf.BSFException: JavaScript Error: Internal Error: org.mozilla.javascript.EcmaError: ReferenceError: "sampler" is not defined.

Steps to Reproduce: 1-Create a Thread Group set to run for two or more iterations 2-Add a Sampler to the Thread Group (tested with an HTTP Sampler) 3-Add a BSF PreProcessor to the Sampler 4-Use javascript as the BSF Language 5-Enter a simple script that references the "sampler" variable. Tested with OUT.println("hello"); OUT.println(sampler); 6-Run

Expected Results:

Actual Results:

Affects Versions:

Created attachment dynamic-forms.jmx: Test Case illustrating issue

dynamic-forms.jmx ````xml false false false 2 1 1 1228306873000 1228306873000 false continue DEADBEE www.blastradius.com / false 0 true true false rfc2109 false bar = true foo false baz = true foo1 false quux = true foo2 www.blastradius.com / POST false true true false false false System.out.println("---"); System.out.println("BeanShell"); System.out.println("Context: " + (ctx == null)); System.out.println("Variables: " + (vars == null)); System.out.println("Sampler: " + (sampler == null)); jexl OUT.println("BSF Jexl"); OUT.println("Context: " + (ctx == null)); OUT.println("Variables: " + (vars == null)); OUT.println("Sampler: " + (sampler == null)); OUT.println("BSF JS"); OUT.println("Context: " + (ctx == null)); OUT.println("Variables: " + (vars == null)); OUT.println("Sampler: " + (sampler == null)); javascript OUT.println("BSF JS (post)"); OUT.println("Context: " + (ctx == null)); OUT.println("Variables: " + (vars == null)); OUT.println("Sampler: " + (sampler == null)); javascript false saveConfig true true true true true true true false true true false false true false false false false false 0 true ````

Severity: normal OS: Mac OS X 10.4

asfimport commented 15 years ago

Thomas Johnson (migrated from Bugzilla): In version 2.3.2, this issue affects both the Pre and Post Processors. As of the current trunk (722032) this only affects the Pre Processor.

asfimport commented 15 years ago

Sebb (migrated from Bugzilla): Thanks for the report and test case.

This appears to be due to a bug in either BSF or Rhino, not JMeter.

It does not appear to be possible to define a script variable with a null value to Javascript using BSF. Furthermore, any variables which are defined after the null value will also be inaccessible.

The null variable in this case is "prev", so a work-round is to ensure that there is at least one previous sample result.

The JMeter code can be rearanged to define the "prev" variable last, but obviously that is also only a work-round.

asfimport commented 15 years ago

Thomas Johnson (migrated from Bugzilla): Some research indicates that BSF used to have an issue with registering (but not declaring) a null bean back in mid-2004 (Ref 1).

From the snippet below, a quick run of the test case shows that BSF Jexl handles the null "prev" object just fine. As BSF Jexl and JS get set up by the same code, it is most likely that the issue lies in or close to Rhino itself.

-- Test Case output -- BSF Jexl Context: false Variables: false Sampler: false BSF JS Context: false Variables: false

-- References -- (1) Commits fixing BSF issue 20355: http://markmail.org/message/ymna5ppb4556og4k

asfimport commented 15 years ago

Sebb (migrated from Bugzilla): As far as I can tell, the problem is in BSF, in the Javascript engine wrapper.

I raised https://issues.apache.org/jira/browse/BSF-22 for the error.

asfimport commented 15 years ago

Sebb (migrated from Bugzilla): I've added a temporary work-round in r724446 and r724445.

This is in the current nightlies (from r724447) if you want to try it out.

asfimport commented 15 years ago

Sebb (migrated from Bugzilla): Please reopen if the fix does not work