Overview of Random Order Controller and Module Controller

Random Order Controller

The Random Order Controller, as a unique logical controller, adds a layer of randomness to the execution of test scripts, making it particularly suitable for simulating uncertain access patterns in user behavior.

Overview of Random Order Controller

The Random Order Controller differs from standard Simple Controllers or Loop Controllers in that it does not execute its child samplers or controllers in a fixed order, but rather in a random sequence. This makes the tests more realistic, especially when simulating situations where users randomly access website pages or server endpoints.

Functional Features

  1. Random Execution Order: Each time the test plan is executed, all child elements under the Random Order Controller will be executed in a completely random order. This helps to simulate the randomness of different users accessing pages or resources.
  2. Ignore Sub-Controller Block: This controller provides an option “Ignore sub-controller block”; if checked, it treats the sub-controller as a single request instead of processing it as a block containing multiple requests. This means the order within the sub-controller will also be randomized and executed as a whole.
  3. Applicable Scenarios: It is very suitable for simulating multi-path access, A/B testing scenarios, or any test cases that require randomization of access patterns.

Usage Steps

  1. Add Random Order Controller: In the JMeter test plan, right-click the parent node (such as Thread Group) where you want to place the Random Order Controller, select “Add” -> “Logic Controller” -> “Random Order Controller”.
  2. Configure Controller: As needed, set a descriptive name for the controller for easy identification. Decide whether to check the “Ignore sub-controller block” option.
  3. Add Child Elements: Under the Random Order Controller, add the samplers or other logical controllers you want to execute randomly.
  4. Run Test: After saving the test plan, run the test. In each iteration, the elements under the controller will be executed in a different random order.

Example Description

We wrote the following script:Overview of Random Order Controller and Module ControllerThread Group: Loop Count set to 2BeanShell Sampler 1: Write the following code

log.info("test1");

BeanShell Sampler 2: Write the following code

log.info("test2");

BeanShell Sampler 3: Write the following code

log.info("test3");

Execute the script and view the JMeter log as follows

2024-06-27 17:30:51,050 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-12024-06-27 17:30:51,061 INFO o.a.j.u.BeanShellTestElement: test12024-06-27 17:30:51,062 INFO o.a.j.u.BeanShellTestElement: test32024-06-27 17:30:51,063 INFO o.a.j.u.BeanShellTestElement: test22024-06-27 17:30:51,064 INFO o.a.j.u.BeanShellTestElement: test12024-06-27 17:30:51,065 INFO o.a.j.u.BeanShellTestElement: test22024-06-27 17:30:51,067 INFO o.a.j.u.BeanShellTestElement: test32024-06-27 17:30:51,093 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1

Executed in random order, this feature is basically consistent with the Logical Controller Random Controller.

Best Practices

● Combine with Timers: To more realistically simulate user behavior, timers can be used under the Random Order Controller to introduce delays.● Pay Attention to Resource Allocation: Ensure that the test design considers the uneven resource allocation that may result from random order, especially when some requests consume more resources than others.● Monitor and Analyze: Use listeners to monitor test results and analyze the impact of random order execution on system performance.

Summary of Random Order Controller

The Random Order Controller is a powerful and flexible component in JMeter that enhances the realism and complexity of tests. By randomizing the execution order of child elements, testers can better simulate unpredictable user traffic patterns, thus improving the effectiveness and coverage of tests. Mastering the use of this controller is crucial for conducting more comprehensive and realistic performance testing.

Module Controller

The Module Controller is an advanced logical controller that provides a powerful mechanism for reusing and organizing components in a test plan. This document will delve into the functions, configuration methods, and application scenarios of the Module Controller.

Functional Overview

The Module Controller allows users to reference another test fragment (usually a simple controller or a test structure under a combination controller) in the test plan and dynamically insert these fragments into the current execution path at runtime. This means you can create generic test modules and reuse them multiple times in different locations as needed, simplifying maintenance and enhancing the flexibility of the test plan.

Usage Scenarios

● Test Fragment Reuse: When you have a complex sequence of requests that need to be executed in multiple places, you can encapsulate it as a module and reference it through the Module Controller to avoid rewriting the same test steps.● Conditional Execution: In conjunction with other logical controllers (such as If Controller), you can decide whether to execute a specific module based on conditions.● Parameterized Testing: By combining user-defined variables or CSV Data Set Config, the Module Controller can execute the same test logic for different data sets.● Test Plan Structure Optimization: Modular design helps maintain the clarity and maintainability of the test plan, especially in large and complex performance testing projects.

Configuration Steps

  1. Create Test Fragment:○ In the test plan, select or create a Thread Group.○ Right-click the Thread Group, select “Add” > “Logic Controller” > “Simple Controller” (or other controllers as module containers).○ Under this new controller, add the samplers, pre-processors, post-processors, and other test elements you need to reuse.
  2. Save Test Fragment (Optional):○ If you want to save this module independently for reuse in other test plans, you can do so using the “Save as Test Fragment” feature.
  3. Add Module Controller:○ Where you want to insert the module, right-click the corresponding logical controller or Thread Group, select “Add” > “Logic Controller” > “Module Controller”.
  4. Configure Module Controller:○ In the properties of the Module Controller, specify the name of the test fragment to reference. This should be the name of the previously created Simple Controller or other controllers.

Application Example

We wrote the following scriptOverview of Random Order Controller and Module ControllerThread Group: Keep defaultBeanShell Sampler 1: Write the following code

log.info("test1");

BeanShell Sampler 2: Write the following code

log.info("test2");

Module Controller: Select Simple Controller 2

After running the script, you can see the JMeter log content as follows

2024-06-28 17:29:19,798 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-12024-06-28 17:29:19,799 INFO o.a.j.u.BeanShellTestElement: test12024-06-28 17:29:19,800 INFO o.a.j.u.BeanShellTestElement: test22024-06-28 17:29:19,800 INFO o.a.j.u.BeanShellTestElement: test22024-06-28 17:29:19,801 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1

You can see that BeanShell Sampler 2 under Simple Controller 2 was executed twice.

Notes

● Ensure that the test fragment referenced by the Module Controller exists in the same test plan or has been correctly imported as a test fragment.● The Module Controller does not pass variables or configurations from its parent scope to the referenced module unless these variables are global.● The execution of the Module Controller does not change the context of the current thread, so the execution results of the samplers are as if they were executed directly within the current Thread Group.

Summary of Module Controller

The Module Controller is a key tool in JMeter for implementing modularization and reuse of test plans. By skillfully applying the Module Controller, test engineers can build more efficient, flexible, and maintainable performance testing solutions. Mastering its usage is crucial for enhancing testing efficiency and quality.

Please open in WeChat client

Leave a Comment