Repeat tests in a schedule
Overview
Schedules containing only user groups and tests run each test in a user group sequentially. To repeat a test for a number of iterations add loops.
Synchronization points are released after the first iteration of the loop and stays released for all further iterations.
You can set a loop within a schedule or a test.
![]()
The following table shows the advantages of both methods:
Loop location Results Schedule Loops in schedules close the server connection at the end of each iteration and reopen it at the beginning of the next iteration. This action models the behavior of a user closing and reopening a browser. Use this method to run a test at a set rate.
Test Loops in tests can be more granular, and thus provide a higher level of control. Loops in tests reuse the server connection during each loop iteration. Use this method, with loops that have high iteration counts, to stress test a server.
Add a loop
To add a loop to a schedule:
- In the Test Navigator, browse to the schedule and double-click it.
- Click the item to be the parent of the loop, and then click Add > Loop.
- In the Schedule Element Details area, set the number of iterations for the loop to repeat.
Option Description Count-based Runs for the number of iterations that you select. Time-based Runs at least for the time that we specify. The loop always finishes the iteration. For example, if you select a time of 1 second and a loop takes 10 seconds to run, the loop finishes one iteration, and then checks the time. Infinite Runs until the schedule duration ends. - To maintain a set transaction rate for all schedule items that are children of this loop:
- Select...
Control the rate of iterations
- In the Iteration rate field, type a number, and select a time unit. This sets the actual rate.
- Select or clear checkbox...
Selecting this check box causes the delay to vary slightly. This option models users more accurately, because the iterations are spread out randomly over a certain period of time.
Delay amounts are set at random from a negative exponential distribution with the same mean as the fixed delay value. The negative exponential distribution has a long "tail," which means that a very small number of delays will have very large values. Verify the application is not negatively affected by long periods of inactivity (such as a timeout that disconnects the user).
- Select or clear the check box...
Delay before the first iteration of the loop
Selecting this check box staggers the first delay in each iteration so that you get a realistic mix at the first iteration.
Example
The following schedule contains two loops. Note that the Browse and Bid tests, which are controlled by the loop, must be children of the loop.
![]()
Implement a conditional loop
A conditional loop runs a specified number of times. Default RPT loop duration options include...
- count-based
- time-based
- infinite options
RPT does not provide a way to dynamically set the target value of the loop. This section discusses how to add a custom Java class that limits the number of iterations of the loop to a finite number.
- Open a new test in Rational Performance Tester
New | New Test
![]()
- Provide a name for the test.
![]()
In the "Protocol and Features" dialog window, only check...
Core Features
![]()
- Add an infinite loop to the test
Click the Add button, and select the Loop element. You can invoke the same context menu by right-clicking the test name...
![]()
- Select the newly added Loop element and then select the Infinite radio button.
![]()
- Select...
Loop element (Right-click) | Add | Custom Code
This Java code will control the number of iterations of the loop.
![]()
We implement separate namespaces for better readability. For example...
mycode.com.AppName.search.SearchLoop
mycode.com.AppName.create.ItemAddLoop- Right-click the loop element, and select...
Insert from the context menu
This class is added to provide a random value to the loop controlling custom code to limit the infinite iterations of the loop to a predetermined value. In real-world scenario, this value can be replaced by any value that you decide to make a loop-breaking condition. You will need to modify the loop control custom code accordingly.
These are the names of the classes in this example...
- Use Add to apply an element after the reference element. Use Insert for one before the reference element. Here, the reference element is the one right-clicked, which is the Loop element in this case.
![]()
- Execute the script
In the example below, the random number generated by mycode.returnRandomValue is 1. The condition check in mycode.controlMyLoop, 2>1, is satisfied, thus the loop is broken on the second execution.
![]()
The conditional check for a number as displayed here can be replaced by any other comparisons. For example, we can use a reference value from an HTTP request, and based upon custom logic, we can break the loop.
Continue a loop with a condition
An added feature of loops is a continue operation. This is useful in certain conditions when you want the loop to skip executing when a certain condition is met. For example, to execute the loop body only for even values up to a maximum value.
We modify the earlier code to include this condition, as well.
Code change required in mycode.controlMyLoop to skip executing the loop body for non-even iterations
public String exec(ITestExecutionServices tes, String[] args) { int i = tes.getLoopControl().getIterationCount(); if(i>Integer.parseInt(args[0])) tes.getLoopControl().breakLoop(); else if(i%2 !=0) tes.getLoopControl().continueLoop(); else tes.getTestLogManager().reportMessage("Iteration No:"+i); return null; }On running the test with those changes, the test logs look something like...
![]()
The random number generated in mycode.returnRandomValue is 9. The loop execution has been skipped for iterations that are not even-numbered, up until the tenth iteration, where the loop is finally broken.
Related:
Schedule overview
User group overview
Working with agents
Related tasks:
Create a schedule
Set user loads
Add a test to a schedule
Assign variables to schedule and user group
Define performance requirements in schedules
Delay virtual users or actions
Run tests at a set rate
Run tests in random order
Add a transaction to a schedule
Synchronize users
Emulate network traffic from multiple hosts
Set log and statistic levels
Add a loop to a test
Error 404 - Not Found Error 404 - Not Found
The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.