0
votes

I'm performing basic API testing of CRUD calls to the database. In JMeter, I have 1 thread with 3 thread groups within my test plan where I've set up Loops and Counters within each thread. The reason for Counters is when saving results to a file, I want to append the file's prefix with the counter value.

The issue is the counters never get reset. So for example:

Where Count = 1 for all groups, I would expect: 
Thread Group 1, filename_1.json
Thread Group 2, filename_2.json
Thread Group 3, filename_3.xml

Where Group 1 Count = 3, Group 2 Count = 2, Group 3 Count = 1, I would expect: 
Thread Group 1, filename_1.json, filename_2.json, filename_3.json
Thread Group 2, filename_4.json and filename_5.json
Thread Group 3, filename_6.xml

Instead, where Count = 1 for all groups I'm getting results like:

Thread Group 1, filename_11.json
Thread Group 2, filename_14.json
Thread Group 3, filename_18.xml

After much searching and trying multiple suggestions, I'm still not getting what I expect. Below is a sample of how the test plan is configured.

Any suggestions are much appreciated.

Thread Group 1
    HTTP Header Manager (application/json)
     Loop Controller
       Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter1)
       HTTP Request (CREATE)
         RegEx (RefName=newRequest, Reg Ex = "id":(.+?)\,"displayName", Template=$1$, Match No.=1, Default=NONE)
          BeanShell Assertion (Name=newRequest, Param=${__setProperty(newRequest,${newRequest},)})
          Save Response to file (File prefix=requestResult_${LoopCounter}, Var Name=newRequestFile)
       Loop Controller
          HTTP Request (READ)
          HTTP Request (UPDATE)
          HTTP Request (DELETE)

Thread Group 2
    HTTP Header Manager (application/json)
     Loop Controller
       Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter2)
       HTTP Request (CREATE)
          RegEx (RefName=newContractId, Reg Ex = "id":(.+?)\,"terminationType", Template=$1$, Match No.=1, Default=NONE)
          BeanShell Assertion (Name=newContractId, Param=${__setProperty(newContractId,${newContractId},)})
          Save Response to file (File prefix=contractRecords_${LoopCounter2}, Var Name=newContractFile)
       Loop Controller
          HTTP Request (READ)
          HTTP Request (UPDATE)
          HTTP Request (DELETE)

Thread Group 3
    HTTP Header Manager (application/xml)
     Loop Controller
       Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter3)
       HTTP Request (CREATE)
          RegEx (RefName=newPricingId, Reg Ex = "id":(.+?)\,"terminationType", Template=$1$, Match No.=1, Default=NONE)
          BeanShell Assertion (Name=newPricingId, Param=${__setProperty(newPricingId,${newPricingId},)})
          Save Response to file (File prefix=pricingRecords_${LoopCounter3}, Var Name=newPricingFile)
       Loop Controller
          HTTP Request (READ)
          HTTP Request (UPDATE)
          HTTP Request (DELETE)

UPDATE

I'm closer to the desired results. With the "Reset counter on each Thread Group" enabled, I would expect Thread Group 2's Count to reset to 0. However, it continues from the previous thread. I need to reset the Counter within each Thread Group. Here's why:

Thread Group 2
   HTTP Header Manager (application/json)
   Loop Controller
      Counter (Start=1, Increment=1, Maximum=100, Num Format=null, Ref Name=LoopCounter2)
      HTTP POST Request (CREATE)
        ${__FileToString(${payloadArchive}/${__eval(contract_${LoopCounter})}.json,,)} 

As you can see, I am passing in a different file into the HTTP Request's body with each loop of Thread Group 2. Each .json file contains unique elements based on the unique constraints of the database. The files are named "contract_01.json", "contract_02.json", "contract_03.json", etc. This is why I want Thread Group 2 to restart it's counter.

1
You say "I have 3 threads" in the description, but your code suggests you have 3 thread groups. So did you mean you have 3 threads in each of the 3 thread groups? Or how many threads each thread group has? Also is "Track Counter Independently for each User" checked? - Kiril S.
Sorry, I only have 1 thread and 3 thread groups. (I corrected that in my orig. statements). With the "Track Counter Independently...." enabled, I'm closer to the desired results. With the "Reset counter on each Thread Group" enabled, I would expect Thread Group 2's Count to reset to 0. However, it continues from the previous thread. I need to reset each Thread Group's Counter to begin at 0. - David

1 Answers

0
votes

SOLVED (?)

The following Counter configurations seem to provide the desired results.

Thread Group 1
    HTTP Header Manager (application/json)
     Loop Controller
       Counter
              Start=null, 
              Increment=null, 
              Maximum=null, 
              Num Format=null, 
              Ref Name=LoopCounter1
       HTTP POST Request (CREATE)
Thread Group 2
    HTTP Header Manager (application/json)
     Loop Controller
       Counter
              Start=1, 
              Increment=null, 
              Maximum=null, 
              Num Format=null, 
              Ref Name=LoopCounter2
       HTTP POST Request (CREATE)
    ${__FileToString(${payloadArchive}/${__eval(contract_${LoopCounter})}.json,,)} 

As you can see, with each loop of Thread Group 2 I am passing in a different file into the HTTP Request's body. (Each file contains unique elements based on the unique constraints of the database.) The files are named "contract_1.json", "contract_2.json", etc. Hence, why I wanted Thread Group 2 to restart its counter.

It is now working and correctly grabbing the correct file contents with each looping. However, I'm not sure why the Start has to be null for Counter 1 and 1 for Counter 2.

If anyone sees a flaw with this, I'd appreciate knowing why and how to correct it. I've only been using JMeter for 1 week with no Java (or any programming) background.