Bug 50032

Summary: Last_Sample_Ok along with other controllers doesnt work correctly when the threadgroup has multiple loops
Product: JMeter - Now in Github Reporter: Deepak Shetty <shettyd>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal CC: p.mouawad
Priority: P1    
Version: 2.5   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Simplified test plan showing the issue
Proposal patch
Shows the issue
CSV file to use with Regression-Script.jmx.
Fix to the issue where If Controller generates additional samples for children Transaction Controller inside when condition is false

Description Deepak Shetty 2010-09-30 13:52:36 UTC
Created attachment 26105 [details]
Simplified test plan showing the issue

if the test plan is
Thread Group (Thread = 1 , Loop =2)
+Sample1
+If Controller (${JMeterThread.last_sample_ok})
++Sample2
++Sample3  (always fails)
++Sample4  (always fails)
Then the test plan executes correctly (i.e. Result is Sample1, Sample2, Sample3(failed) ,Sample1, Sample2, Sample3(failed)


However if now we add a Simple Controller so that the plan is
Thread Group (Thread = 1 , Loop =2)
+Sample1
+If Controller (${JMeterThread.last_sample_ok})
++Sample2
++Simple Controller
+++Sample3  (always fails)
+++Sample4  (always fails)

Then the test plan executes incorrectly(i.e. Result is Sample1, Sample2, Sample3(failed) ,Sample1, Sample2, Sample4(failed)

The only workaround I can see is to not have the simple controller (but other controllers like the IF will similarly impact the behavior so this isnt very viable)
Comment 1 Milamber 2010-10-09 17:18:40 UTC
Created attachment 26151 [details]
Proposal patch
Comment 2 Milamber 2010-10-09 17:19:07 UTC
Thanks for your report and test script.

This bug comes from a Simple controller's index which is not reinitialized on loop 2 (the next is sample 4 - not the sample 3)
Solution: when "If Controller" breaks tree execution (after Sample 3 fails) run a reinitialization indexes on sub-controllers.

in attachment, a proposal patch.
@sebb: have you a comment before I commit the patch?
Comment 3 Sebb 2010-10-11 12:16:43 UTC
Patch looks fine to me, except that I think the method reInitializeSubController() should be protected rather than public.

[It can always be made public later if it proves necessary.]
Comment 4 Milamber 2010-10-11 17:34:30 UTC
Thanks; fixed in SVN (and next nightly build):

URL: http://svn.apache.org/viewvc?rev=1021512&view=rev
Log:
Bug 50032 - Last_Sample_Ok along with other controllers doesnt work correctly when the threadgroup has multiple loops

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
    jakarta/jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java

URL: http://svn.apache.org/viewvc?rev=1021514&view=rev

Modified:
    jakarta/jmeter/trunk/xdocs/changes.xml
Comment 5 Milamber 2011-01-21 03:26:14 UTC
URL: http://svn.apache.org/viewvc?rev=1061679&view=rev
Log:
No need to return a value (improving patch Bug 50032)

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
Comment 6 Philippe Mouawad 2011-09-12 07:12:07 UTC
Hello,
This patch introduced a regression on IfController.
Attached is a scenario that shows how an Infinite Loop will occur when a IfController contains a TransactionController.
If condition evaluates to false, reInitializeSubController will loop infinitely.

I don't know if this reopening is a duplicate of 50618 but maybe another manifestation of the regression.

Regards
Philippe Mouawad
Comment 7 Philippe Mouawad 2011-09-12 07:13:09 UTC
Created attachment 27486 [details]
Shows the issue
Comment 8 Philippe Mouawad 2011-09-12 07:13:35 UTC
Created attachment 27487 [details]
CSV file to use with Regression-Script.jmx.
Comment 9 Philippe Mouawad 2011-09-12 09:19:52 UTC
Hello,
There is another issue with patch, it's that it generates additional samples for transactions inside IfCOntroller due to the call to nextIsAController() inside reInitializeSubController.

For example when line in CSV is equal to 0, I get in "View Results Tree" calls to:
- s3-createAddressAndHousing
- S3-createLegalEntityAddress

although sampler inside these are not executed.

Regards
Philippe
Comment 10 Milamber 2011-09-13 23:36:46 UTC
(In reply to comment #6)

Thanks. Fixed.

URL: http://svn.apache.org/viewvc?rev=1170388&view=rev
Log:
If Controller - Fixed a regression introduce by bug 50032
See: https://issues.apache.org/bugzilla/show_bug.cgi?id=50032#c6
and https://issues.apache.org/bugzilla/show_bug.cgi?id=50618#c28

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java
    jakarta/jmeter/trunk/xdocs/changes.xml
Comment 11 Philippe Mouawad 2011-09-14 07:17:12 UTC
Thank you for applying.
Maybe a note should be added in Known issues regarding the incomplete fix of this isssue:
- Currently it generates additional samples for transactions inside IfCOntroller due to the call to nextIsAController() inside reInitializeSubController.

Even if sampler are not run.
I don't know if you close this issue and open another bug or you keep this one opened.

Regards
Philippe
Comment 12 Milamber 2011-09-14 16:44:07 UTC
URL: http://svn.apache.org/viewvc?rev=1170707&view=rev
Log:
Add two knows issues : bug 50032 and bug 50618

Modified:
    jakarta/jmeter/trunk/xdocs/changes.xml
Comment 13 Philippe Mouawad 2011-09-17 12:36:29 UTC
Created attachment 27519 [details]
Fix to the issue where If Controller generates additional samples for children Transaction Controller inside when condition is false

Hello,
Here is a fix to the known issue related to this bug:
-If Controller generates additional samples for children Transaction Controller inside when condition is false.

Here is how it works, once a thread enters reInitializeSubController() it flags the JMeterThreadContext if it's the first Parent.
In TransactionController listeners will not be notified that a sample occured since it didn't .
Once the first Parent has finished reinitializing, it unsets the flag in finally.

I tested with attached JMX and it works.
Regards
Philippe
Comment 14 Milamber 2011-09-17 15:06:22 UTC
Philippe, your patch don't respect code style used in JMeter. 

== No good ==
         }
         finally
         {
== Good ==
         } finally {
==========



== No good ==
         if(isReinitializingSubControllers)
         {
             isReinitializingSubControllers = false;
         }
         else
         {
             log.warn("Unsetting while flag is not true");
         }
== Good ==
         if (isReinitializingSubControllers) {  // please note: one space before left parenthesis
             isReinitializingSubControllers = false;
         } else {
             log.warn("Unsetting while flag is not true");
         }
=======

Comments on source code don't need have all characters in uppercase

=======

"@see" must follow by a classname, not a "ISSUE" keyword.

Please respect code style convention in JMeter for next submissions. Thanks.
Comment 15 Milamber 2011-09-17 15:09:46 UTC
Thanks for patch (even if it didn't follow code style :))
Applied.

Now, I close the bug. Thanks Phillippe.

URL: http://svn.apache.org/viewvc?rev=1171999&view=rev
Log:
Bug 50032 - Fixed a new regression introduced by bug 50032 when Transaction Controller is a child of If Controller

Modified:
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/GenericController.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java
    jakarta/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterContext.java
    jakarta/jmeter/trunk/xdocs/changes.xml
Comment 16 Philippe Mouawad 2011-09-17 15:16:56 UTC
I am sorry for not respecting, I missed it.
I will take care next time, anyway thanks for taking it as is.
Regards
Philippe.
Comment 17 The ASF infrastructure team 2022-09-24 20:37:45 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2405