Locust Performance-Zero Foundation Entry Series (7)

This article mainly explains the use of TaskSet class to manage test scenarios. Especially when there are more and more function points to be included in the test scope, it is more necessary to consider test management related content. Make performance testing more organized and efficient.
Use the following official examples to explain the usage of TaskSet and some details in the test run.

from locust import User, TaskSet, between,task,constant

class ForumSection(TaskSet):
    wait_time = constant(1)
    @task(10)
    def view_thread(self):
        print("This is task viewThread")

    @task(1)
    def create_thread(self):
        print("This is task create thread")

    @task(1)
    def stop(self):
        self.interrupt()

class LoggedInUser(User):
    wait_time = between(5,10)
    tasks = {ForumSection:2}

    @task
    def index_page(self):
        print("this is a index page.")

As above, the ForumSection class inherits the TaskSet class, which defines 3 tasks, 1 and 2 are more conventional tasks, where the weight of view_thread is 10, and the weight of create_thread is 1. In addition, there is a special task-> "stop" , The weight of this task is 1. If the task thread selects this method, it will end the execution of the thread in this task set (TaskSet) and fall back to its parent node (parent TaskSet).

Taken together, here are some key points of using this mode to manage performance testing.

  • The custom TaskSet subclass must inherit the TaskSet class

  • If the TaskSet class sets test runtime parameters, such as wait_time, then the TaskSet class settings prevail. If there are no parameters set in the TaskSet class, then the settings in the User class will be used.

  • If a thread (user) executes the stop task in the TaskSet class, then the thread will jump back to the parent node, in this case, jump back to the user class LoggedInUser, then the next step, the thread may perform the task "Index_page", it is also possible to perform the task "ForumSection". And so on.

  • When the TaskSet class executes a task, it takes all eligible tasks in the TaskSet class as the scope, and tasks outside the TaskSet class are not within the weight calculation range.

In addition, I have a locust basic course https://edu.51cto.com/sd/ddd95 in 51CTO Academy , please check if necessary.

Guess you like

Origin blog.51cto.com/13734261/2551636