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.11k stars 2.06k forks source link

Functions are invoked additional times when used in combination with a Config Element #2356

Closed asfimport closed 12 years ago

asfimport commented 14 years ago

Radu Leterna (Bug 48943):

  1. Create a new JMeter Test Plan

  2. Add a Thread Group and set: Number of Threads=1 Loop Count=5

  3. Add a Bean Shell sampler to your Thread Group and in the "Script" section add the following two lines: //${StringFromFile(Values.txt,readValues)} System.out.println("__ " + "${readValues}" + " ")

  4. Add a Simple Config Element to your Thread Group.

  5. Save the Test Plan in the {JMETER_HOME}/bin folder.

  6. Create a txt file called "Values.txt" in the {JMETER_HOME}/bin folder.

  7. Fill in at least 10 lines in the file with some values (E.g. : numbers from 0 to 9).

  8. Save the text file and close it.

  9. Open your previous created JMeter test plan and run the test.

Expected result: On the command window that opens with JMeter you can see the output of the test. We are expecting to see the first 5 values (5 lines) from the txt file.

Actual result: After JMeter reads a line from the file, it will skip the next line. So, you will have displayed the lines 1,3,5,7,9. If you disable the Simple Config Element and run the test again, you will notice that the behavior is the expected one. Also, this only reproduces when using loops. If you put, for example, 5 threads and 1 loop, the values will be correctly displayed.

I attached to this bug a test plan and a data file that can be used to reproduce this bug, so you don't have to build your test again. Just unzip the files in the {JMETER_HOME}/bin folder and run the test.

Created attachment bin.zip: JMeter Test Plan used to reproduce this bug.

Severity: normal OS: All

asfimport commented 14 years ago

Radu Leterna (migrated from Bugzilla): Changing priority since this is a very important problem for our project.

asfimport commented 14 years ago

Sebb (migrated from Bugzilla): Sorry, but the priority is used to indicate the effect of the bug on the general behaviour of JMeter.

I don't know how long it will take to fix this, so I suggest you try using the CSV Dataset Config element to try reading the file.

asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): Hello, The issue occurs because ConfigTestElement ends up setting temporaryProperties in AbstractTestElement#temporaryProperties which is not null anymore.

Then during the call of JMeterThread#notifyTestListeners, we end up calling recoverRunningVersion on each TestElement. This method does this: => if (isTemporary(prop)) { iter.remove(); clearTemporary(prop); }

isTemporary calls : temporaryProperties.contains(property);

This one ends up calling FunctionProperty#hashCode which call super.hashCode => AbstractProperty#hashCode which call getStringValue() which executes the BeanShell script again through this condition: if (iter > testIteration || cacheValue == null) { testIteration = iter; cacheValue = function.execute(); }

=> Which leads to the issue. execute is called outside of Sampling.

So this issue could occur as long as setTemporary is called on AbstractTestElement, so it is a big issue I think.

Now for the fix, I don't have the full code history, but I think that fix should be in:

I find it strange that equals and hashCode does not work on same datas.

Please find a patch but have a critical review of it. I tested on submitted case and it works.

Regards Philippe Mouawad

asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): Patch as described in previous comment

Created attachment 48943.patch: Patch to FunctionProperty#hashCode

48943.patch ````diff Index: src/core/org/apache/jmeter/testelement/property/FunctionProperty.java =================================================================== --- src/core/org/apache/jmeter/testelement/property/FunctionProperty.java (revision 1166194) +++ src/core/org/apache/jmeter/testelement/property/FunctionProperty.java (working copy) @@ -64,10 +64,11 @@ @Override public int hashCode(){ - int hash = super.hashCode(); + if (function != null) { - hash = hash*37 + function.hashCode(); + return function.hashCode(); } + int hash = super.hashCode(); return hash; } ````
asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): I think Bug should be renamed, FunctionProperty#function is reexecuted abusively by hashCode if inside a loop controller.

asfimport commented 12 years ago

@pmouawad (migrated from Bugzilla): Initial Values.txt makes parse error failures. This one is OK.

Created attachment Values.txt: Values.txt that work

Values.txt ```` 111111 222222 333333 444444 555555 666666 777777 888888 999999 000000 AAAAAA BBBBBB CCCCCC DDDDDD EEEEEE FFFFFF GGGGGG HHHHHH IIIIII JJJJJJ KKKKKK LLLLLL MMMMMM NNNNNN OOOOOO PPPPPP RRRRRR SSSSSS TTTTTT UUUUUU````
asfimport commented 12 years ago

Sebb (migrated from Bugzilla): Thanks for the analysis; looks good.

A different approach might be to change the parent hashCode() and equals() to use getObjectValue() instead, as that does not execute functions.

Indeed, does it make sense to use a hash and equals methods that can vary between invocations for the same object?

Or possibly even drop the methods entirely and rely on Object equals and hashCode?

Need to do some testing to see whether distinct Property objects need to compare equal.

asfimport commented 12 years ago

Sebb (migrated from Bugzilla): The unit tests still work if equals and hashCode in AbstractProperty are changed to use getObjectValue(), and that also fixes the issue whereby values are skipped because the function is evaluated when it should not be.

Using the object value also avoids the string conversions that are otherwise done.

So although your fix works, I think it would be better to fix the parent class.

BTW, a simpler test is to just use:

System.out.println("${__counter(FALSE)}");

asfimport commented 12 years ago

Sebb (migrated from Bugzilla): Curiously, I have so far been unable to provoke the issue with anything but the BeanShell sampler.

Even when this is fixed, however, using a function call in a test element Name field is likely to cause spurious function evaluations. Not sure why this is.

asfimport commented 12 years ago

Sebb (migrated from Bugzilla): More general subject

asfimport commented 12 years ago

Sebb (migrated from Bugzilla): Fixed in SVN

URL: http://svn.apache.org/viewvc?rev=1170595&view=rev Log: https://github.com/apache/jmeter/issues/2356 - Functions are invoked additional times when used in combination with a Config Element

Modified: jakarta/jmeter/trunk/bin/testfiles/BatchTestLocal.csv jakarta/jmeter/trunk/bin/testfiles/BatchTestLocal.jmx jakarta/jmeter/trunk/bin/testfiles/BatchTestLocal.xml jakarta/jmeter/trunk/src/core/org/apache/jmeter/testelement/property/AbstractProperty.java jakarta/jmeter/trunk/xdocs/changes.xml