Bug 38646 - regular expression extractor using random match number doesn't reset variable in loop
Summary: regular expression extractor using random match number doesn't reset variable...
Status: RESOLVED FIXED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 2.1.1
Hardware: Other Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: JMeter issues mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-14 21:44 UTC by Greg
Modified: 2006-02-18 10:22 UTC (History)
0 users



Attachments
a test which recreates the problem (20.54 KB, text/plain)
2006-02-14 22:53 UTC, Greg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Greg 2006-02-14 21:44:58 UTC
I'm using the expression extractor to generate a variable on a random match. 
And then using an "if controller" to run a test based on finding that match. 
But it looks like there is a bug when I run the test multiple times in a loop. 
When the match is found on a previous loop, but not a subsequent one, it seems
not to reset the variable to it's default.  Try running the following test and
you'll notice that some "If 1" components are called after the "sample 1"
clearly does not match the expression "a b c 2 d".

---- jmx test below this line --------------------------------------
<jmeterTestPlan version="1.1" properties="1.7">
  <hashTree>
    <TestPlan>
      <elementProp name="TestPlan.user_defined_variables"
elementType="org.apache.jmeter.config.Arguments">
        <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>
        <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>
        <collectionProp name="Arguments.arguments"/>
        <stringProp name="TestElement.name">User Defined Variables</stringProp>
        <boolProp name="TestElement.enabled">true</boolProp>
      </elementProp>
      <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.TestPlanGui</stringProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <stringProp
name="TestElement.test_class">org.apache.jmeter.testelement.TestPlan</stringProp>
      <stringProp name="TestElement.name">Test Plan</stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestElement.enabled">true</boolProp>
      <stringProp name="TestPlan.comments"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup>
        <longProp name="ThreadGroup.start_time">1076438592000</longProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <stringProp
name="TestElement.test_class">org.apache.jmeter.threads.ThreadGroup</stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <boolProp name="TestElement.enabled">true</boolProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp
name="TestElement.gui_class">org.apache.jmeter.threads.gui.ThreadGroupGui</stringProp>
        <elementProp name="ThreadGroup.main_controller"
elementType="org.apache.jmeter.control.LoopController">
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.LoopControlPanel</stringProp>
          <stringProp name="LoopController.loops">10</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.control.LoopController</stringProp>
          <stringProp name="TestElement.name">Loop Controller</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
          <boolProp name="LoopController.continue_forever">false</boolProp>
        </elementProp>
        <stringProp name="TestElement.name">ForEach Controller</stringProp>
        <longProp name="ThreadGroup.end_time">1076438592000</longProp>
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
      </ThreadGroup>
      <hashTree>
        <org.apache.jmeter.config.Arguments>
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>
          <collectionProp name="Arguments.arguments">
            <elementProp name="returnVar"
elementType="org.apache.jmeter.config.Argument">
              <stringProp name="Argument.metadata">=</stringProp>
              <stringProp name="Argument.value"></stringProp>
              <stringProp name="Argument.name">returnVar</stringProp>
            </elementProp>
          </collectionProp>
          <stringProp name="TestElement.name">User Defined Variables</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
        </org.apache.jmeter.config.Arguments>
        <hashTree/>
        <JavaSampler>
          <elementProp name="arguments"
elementType="org.apache.jmeter.config.Arguments">
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>
            <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>
            <collectionProp name="Arguments.arguments">
              <elementProp name="Sleep_Time"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value">100</stringProp>
                <stringProp name="Argument.name">Sleep_Time</stringProp>
              </elementProp>
              <elementProp name="Sleep_Mask"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value">0xFF</stringProp>
                <stringProp name="Argument.name">Sleep_Mask</stringProp>
              </elementProp>
              <elementProp name="Label"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value">Sample 1</stringProp>
                <stringProp name="Argument.name">Label</stringProp>
              </elementProp>
              <elementProp name="ResponseCode"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value">200</stringProp>
                <stringProp name="Argument.name">ResponseCode</stringProp>
              </elementProp>
              <elementProp name="ResponseMessage"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value"></stringProp>
                <stringProp name="Argument.name">ResponseMessage</stringProp>
              </elementProp>
              <elementProp name="Status"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value">OK</stringProp>
                <stringProp name="Argument.name">Status</stringProp>
              </elementProp>
              <elementProp name="SamplerData"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value"></stringProp>
                <stringProp name="Argument.name">SamplerData</stringProp>
              </elementProp>
              <elementProp name="ResultData"
elementType="org.apache.jmeter.config.Argument">
                <stringProp name="Argument.metadata">=</stringProp>
                <stringProp name="Argument.value">a b c
${__Random(1,2,&quot;randnum&quot;)} d</stringProp>
                <stringProp name="Argument.name">ResultData</stringProp>
              </elementProp>
            </collectionProp>
            <stringProp name="TestElement.name"></stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
          </elementProp>
          <stringProp
name="classname">org.apache.jmeter.protocol.java.test.JavaTest</stringProp>
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.java.control.gui.JavaTestSamplerGui</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.protocol.java.sampler.JavaSampler</stringProp>
          <stringProp name="TestElement.name">Sample 1</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
        </JavaSampler>
        <hashTree>
          <RegexExtractor>
            <stringProp name="RegexExtractor.default">fout</stringProp>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.extractor.gui.RegexExtractorGui</stringProp>
            <stringProp
name="TestElement.test_class">org.apache.jmeter.extractor.RegexExtractor</stringProp>
            <stringProp name="RegexExtractor.regex">a b (\w) 2 d</stringProp>
            <stringProp name="TestElement.name">Regex 1</stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
            <stringProp name="RegexExtractor.useHeaders">false</stringProp>
            <stringProp name="RegexExtractor.template">$1$</stringProp>
            <stringProp name="RegexExtractor.match_number">0</stringProp>
            <stringProp name="RegexExtractor.refname">inputVar</stringProp>
          </RegexExtractor>
          <hashTree/>
        </hashTree>
        <org.apache.jmeter.control.ForeachController>
          <stringProp name="ForeachController.inputVal">inputVar_g</stringProp>
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.ForeachControlPanel</stringProp>
          <stringProp name="ForeachController.returnVal">returnVar</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.control.ForeachController</stringProp>
          <stringProp name="TestElement.name">ForEach 1</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
          <boolProp name="ForeachController.useSeparator">false</boolProp>
        </org.apache.jmeter.control.ForeachController>
        <hashTree>
          <JavaSampler>
            <elementProp name="arguments"
elementType="org.apache.jmeter.config.Arguments">
              <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>
              <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>
              <collectionProp name="Arguments.arguments">
                <elementProp name="Sleep_Time"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">100</stringProp>
                  <stringProp name="Argument.name">Sleep_Time</stringProp>
                </elementProp>
                <elementProp name="Sleep_Mask"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">0xFF</stringProp>
                  <stringProp name="Argument.name">Sleep_Mask</stringProp>
                </elementProp>
                <elementProp name="Label"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">For 1 ${returnVar} to
${inputVar_g1}</stringProp>
                  <stringProp name="Argument.name">Label</stringProp>
                </elementProp>
                <elementProp name="ResponseCode"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">200</stringProp>
                  <stringProp name="Argument.name">ResponseCode</stringProp>
                </elementProp>
                <elementProp name="ResponseMessage"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value"></stringProp>
                  <stringProp name="Argument.name">ResponseMessage</stringProp>
                </elementProp>
                <elementProp name="Status"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">OK</stringProp>
                  <stringProp name="Argument.name">Status</stringProp>
                </elementProp>
                <elementProp name="SamplerData"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">${returnVar1}</stringProp>
                  <stringProp name="Argument.name">SamplerData</stringProp>
                </elementProp>
                <elementProp name="ResultData"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value"></stringProp>
                  <stringProp name="Argument.name">ResultData</stringProp>
                </elementProp>
              </collectionProp>
              <stringProp name="TestElement.name"></stringProp>
              <boolProp name="TestElement.enabled">true</boolProp>
            </elementProp>
            <stringProp
name="classname">org.apache.jmeter.protocol.java.test.JavaTest</stringProp>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.java.control.gui.JavaTestSamplerGui</stringProp>
            <stringProp
name="TestElement.test_class">org.apache.jmeter.protocol.java.sampler.JavaSampler</stringProp>
            <stringProp name="TestElement.name">For 1</stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
          </JavaSampler>
          <hashTree/>
        </hashTree>
        <IfController>
          <stringProp name="IfController.condition">&quot;${inputVar_g1}&quot;
== &quot;c&quot;</stringProp>
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.control.gui.IfControllerPanel</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.control.IfController</stringProp>
          <stringProp name="TestElement.name">If Controller</stringProp>
          <boolProp name="TestElement.enabled">true</boolProp>
        </IfController>
        <hashTree>
          <JavaSampler>
            <elementProp name="arguments"
elementType="org.apache.jmeter.config.Arguments">
              <stringProp
name="TestElement.gui_class">org.apache.jmeter.config.gui.ArgumentsPanel</stringProp>
              <stringProp
name="TestElement.test_class">org.apache.jmeter.config.Arguments</stringProp>
              <collectionProp name="Arguments.arguments">
                <elementProp name="Sleep_Time"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">100</stringProp>
                  <stringProp name="Argument.name">Sleep_Time</stringProp>
                </elementProp>
                <elementProp name="Sleep_Mask"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">0xFF</stringProp>
                  <stringProp name="Argument.name">Sleep_Mask</stringProp>
                </elementProp>
                <elementProp name="Label"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">If 1 ${returnVar} to
${inputVar_g1}</stringProp>
                  <stringProp name="Argument.name">Label</stringProp>
                </elementProp>
                <elementProp name="ResponseCode"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">200</stringProp>
                  <stringProp name="Argument.name">ResponseCode</stringProp>
                </elementProp>
                <elementProp name="ResponseMessage"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value"></stringProp>
                  <stringProp name="Argument.name">ResponseMessage</stringProp>
                </elementProp>
                <elementProp name="Status"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">OK</stringProp>
                  <stringProp name="Argument.name">Status</stringProp>
                </elementProp>
                <elementProp name="SamplerData"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value">${returnVar1}</stringProp>
                  <stringProp name="Argument.name">SamplerData</stringProp>
                </elementProp>
                <elementProp name="ResultData"
elementType="org.apache.jmeter.config.Argument">
                  <stringProp name="Argument.metadata">=</stringProp>
                  <stringProp name="Argument.value"></stringProp>
                  <stringProp name="Argument.name">ResultData</stringProp>
                </elementProp>
              </collectionProp>
              <stringProp name="TestElement.name"></stringProp>
              <boolProp name="TestElement.enabled">true</boolProp>
            </elementProp>
            <stringProp
name="classname">org.apache.jmeter.protocol.java.test.JavaTest</stringProp>
            <stringProp
name="TestElement.gui_class">org.apache.jmeter.protocol.java.control.gui.JavaTestSamplerGui</stringProp>
            <stringProp
name="TestElement.test_class">org.apache.jmeter.protocol.java.sampler.JavaSampler</stringProp>
            <stringProp name="TestElement.name">If 1</stringProp>
            <boolProp name="TestElement.enabled">true</boolProp>
          </JavaSampler>
          <hashTree/>
        </hashTree>
        <ResultCollector>
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.visualizers.ViewResultsFullVisualizer</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.reporters.ResultCollector</stringProp>
          <stringProp name="TestElement.name">View Results Tree</stringProp>
          <objProp>
            <value class="org.apache.jmeter.samplers.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>true</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
             
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
              <delimiter>,</delimiter>
              <printMilliseconds>true</printMilliseconds>
            </value>
            <name>saveConfig</name>
          </objProp>
          <boolProp name="TestElement.enabled">true</boolProp>
          <stringProp name="filename"></stringProp>
          <boolProp name="ResultCollector.error_logging">false</boolProp>
        </ResultCollector>
        <hashTree/>
        <ResultCollector>
          <stringProp
name="TestElement.gui_class">org.apache.jmeter.visualizers.TableVisualizer</stringProp>
          <stringProp
name="TestElement.test_class">org.apache.jmeter.reporters.ResultCollector</stringProp>
          <stringProp name="TestElement.name">View Results in Table</stringProp>
          <objProp>
            <value class="org.apache.jmeter.samplers.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>true</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
             
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
              <delimiter>,</delimiter>
              <printMilliseconds>true</printMilliseconds>
            </value>
            <name>saveConfig</name>
          </objProp>
          <boolProp name="TestElement.enabled">true</boolProp>
          <stringProp name="filename"></stringProp>
          <boolProp name="ResultCollector.error_logging">false</boolProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>
Comment 1 Sebb 2006-02-14 22:36:40 UTC
Sorry to ask, but please can you attach the test script as a separate file,
rather than in-line?

It's rather tedious having to extract it and fix up any bad line breaks.

Thanks!
[The attach link only appears once an issue has been created]
Comment 2 Greg 2006-02-14 22:53:14 UTC
Created attachment 17697 [details]
a test which recreates the problem

Here is the file as an attachment.
Comment 3 Greg 2006-02-14 23:02:48 UTC
Basically, I hit this because I'm trying to write a test that parses a web page
with possible page ranges (like google search results), and then go to a random
page within the results.  So when I look for href's with something like
?page=55",  it works the first time.  But when run in a loop, and the second
search doesn't return any pages, it still has the variable set with the first
results (55).

Comment 4 Sebb 2006-02-18 17:34:00 UTC
Thanks for the update.

The code for resetting the previous values of the _gn variables is currently
only invoked where the match number is < 0 - the negative number was spefically
designed for use with the For Controller.

I'll fix this, but in the meantime, using ${inputVar} rather than ${inputVar_g1}
should fix the problem for the If controller.
Comment 5 Sebb 2006-02-18 19:22:56 UTC
Test cases and fix have been applied to 2.1 branch. Note that only _g0 and _g1
variables are currently cleared.

The code now additionally sets refName_g to the number of groups in the RE (in
case that is useful)

The code will be in the next nightly.
Comment 6 The ASF infrastructure team 2022-09-24 20:37:36 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/1681