Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Loop controller with 0 iterations, stops evaluating the iterations field #1819

Closed
asfimport opened this issue Oct 31, 2006 · 3 comments
Closed

Comments

@asfimport
Copy link
Collaborator

Nikolay Diakov (Bug 40851):
We have a "loop" controler, the number of iterations of which depends on a
BeanShell function. That function returns random number in some integer range.
When the function returns a 0, the "loop" controller code re-evaluating the
iterations field! This means if we want to run a user thread of Bug 1000 runs with
a "loop" controler that does iterations 3, 2, 4, 1, 0, 3, 2, 4, 1, 0, ... and
so on each user run, the first time the iteration number hits 0, it stays 0.

We made a work around with an "if" controller that checks whether we have a 0
and does not pass it to the loop controller.

Cheers,
Nik

OS: Windows XP

@asfimport
Copy link
Collaborator Author

Alf Hogemark (migrated from Bugzilla):
You will need to make a CSV file named "no_iterations.csv", with the number of
iteration of the loop for each iteration of the threadgroup, for example like
this :
2
1
0
3

You will see that you only get 3 samples (2+1).

Created attachment test_loop_with_variable_iterations.jmx: Test plan to show the bug

test_loop_with_variable_iterations.jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="1.8">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
        <stringProp name="TestPlan.comments"></stringProp>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <stringProp name="TestPlan.comments"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
        <longProp name="ThreadGroup.start_time">1178869614000</longProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop for ThreadGroup Thread Group" enabled="true">
          <stringProp name="LoopController.loops">4</stringProp>
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="TestPlan.comments"></stringProp>
        </elementProp>
        <longProp name="ThreadGroup.end_time">1178869614000</longProp>
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <stringProp name="TestPlan.comments"></stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
      </ThreadGroup>
      <hashTree>
        <CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="CSVDataSet" enabled="true">
          <stringProp name="delimiter">,</stringProp>
          <stringProp name="variableNames">no_iterations</stringProp>
          <boolProp name="recycle">true</boolProp>
          <stringProp name="filename">no_iterations.csv</stringProp>
          <stringProp name="TestPlan.comments"></stringProp>
          <stringProp name="fileEncoding"></stringProp>
        </CSVDataSet>
        <hashTree/>
        <LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <stringProp name="LoopController.loops">${no_iterations}</stringProp>
          <boolProp name="LoopController.continue_forever">true</boolProp>
          <stringProp name="TestPlan.comments"></stringProp>
        </LoopController>
        <hashTree>
          <HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="A" enabled="true">
            <stringProp name="HTTPSampler.path">/</stringProp>
            <stringProp name="HTTPSampler.method">GET</stringProp>
            <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
            <stringProp name="HTTPSampler.protocol"></stringProp>
            <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
            <stringProp name="HTTPSampler.contentEncoding"></stringProp>
            <stringProp name="HTTPSampler.port"></stringProp>
            <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
              <collectionProp name="Arguments.arguments"/>
              <stringProp name="TestPlan.comments"></stringProp>
            </elementProp>
            <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
            <stringProp name="HTTPSampler.mimetype"></stringProp>
            <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
            <stringProp name="HTTPSampler.monitor">false</stringProp>
            <stringProp name="HTTPSampler.domain">www.google.no</stringProp>
            <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
            <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
            <stringProp name="TestPlan.comments"></stringProp>
            <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          </HTTPSampler>
          <hashTree/>
        </hashTree>
        <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
          <objProp>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>false</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
            </value>
            <name>saveConfig</name>
          </objProp>
          <stringProp name="filename"></stringProp>
          <stringProp name="TestPlan.comments"></stringProp>
          <boolProp name="ResultCollector.error_logging">false</boolProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

@asfimport
Copy link
Collaborator Author

Alf Hogemark (migrated from Bugzilla):
This suggested patch causes the the loop evaluation to be executed on each
iteration, even if the loop has had a "Loop count" of value 0 in earlier
iterations.

This can be useful for example if you are looping over company and their
customers as an example. If some company has 0 customers, this bug means that
the "customers" loop will never again be entered, even if the next company has
4 customers.

Created attachment patch_for_40851.patch: Suggested patch

patch_for_40851.patch
Index: C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/core/org/apache/jmeter/control/LoopController.java
===================================================================
--- C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/core/org/apache/jmeter/control/LoopController.java	(revision 536755)
+++ C:/Documents and Settings/alf.hogemark/workspace/Jmeter 2.2 official/src/core/org/apache/jmeter/control/LoopController.java	(working copy)
@@ -78,17 +78,19 @@
 		return getPropertyAsBoolean(CONTINUE_FOREVER);
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.control.Controller#isDone()
-	 */
-	public boolean isDone() {
-		if (getLoops() != 0) {
-			return super.isDone();
-		}
-		return true;
-	}
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jmeter.control.Controller#next()
+     */
+    public Sampler next() {
+        if(endOfLoop()) {
+            return null;
+        }
+        else {
+            return super.next();
+        }
+    }
 
 	private boolean endOfLoop() {
 		return (getLoops() > -1) && loopCount >= getLoops();

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
Thanks - applied to SVN in r537660

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant