LOCUST를 이용한 부하 테스트

이동욱

2021/10/21

Categories: 기타

LOCUST를 선택한 이유


설치 방법


pip3 install locust

테스트 방법


from locust import HttpUser, task

class HelloWorldUser(HttpUser):
  @task
   def hello_world(self):
     self.client.get("/hello")
     self.client.get("/world")
locust --host="server address"

from random import randint
from locust import HttpUser, task


class UserBehavior(HttpUser):

    def on_start(self):
        self.login()

    def on_stop(self):
        self.logout()

    def login(self):
        response = self.client.post("/api/v1/auth/login", json={"user-id": "id",
                                                                "user-pwd": "pass"})
        access_token = response.json()['data']['access_token']
        self.client.headers.update({'Authorization': 'Bearer ' + access_token})

        # # user info
        self.user_company_key = response.json()['data']['user_info']['company_key']

    def logout(self):
        self.client.delete("/api/v1/auth/logout_access_token")

    # 조회
    @task
    def view_dashboard(self):
        """
        HOME - DASH BOARD
        """
        # get list
        response = self.client.get('/api/v1/dashboard/summary-info?role=ADMIN&company_key=26')
        response = self.client.get('/api/v1/notice/dashboard-notices?company_key=26')
        response = self.client.get('/api/v1/group/groups?show_deleted=0&company_key=26&by_requestor=0')
        response = self.client.get('/api/v1/dashboard/compliance-list?offset=0&count=12&group_list=&company_key=26')

    @task
    def view_home_notice(self):
        """
        HOME - NOTICE
        """
        # get list
        response = self.client.get(
            '/api/v1/notice/notices?offset=0&count=20&company_key=26&show_deleted=0&is_cm=1&is_admin=1&is_service_admin=0')

    @task
    def view_training_my_training_to_do_list(self):
        """
        TRAINING - MY TRAINING - TO DO LIST
        """
        # get list
        response = self.client.get(
            '/api/v1/contents/my-lecture/to-do-list?show_deleted=0&offset=0&count=20&category_list=&my_status=NOT+OPEN,+IN+PROGRESS,+OVERDUE&status_list=ACTIVE,+EXPIRED&after_active_date=1&exclude_previous=1&validity=1&company_key=26')

    @task
    def view_training_my_training_optional_list(self):
        """
        TRAINING - MY TRAINING - OPTIONAL
        """
        # get list
        response = self.client.get(
            '/api/v1/contents/lectures?show_deleted=0&offset=0&count=20&status=ACTIVE&training_type=OPTIONAL&category_list=&attended=0&validity=1&my_lecture=0&sorting_mode=due_date_desc&exclude_previous=1&type=LECTURE&company_key=26')

    @task
    def view_training_my_training_all_lectures(self):
        """
        TRAINING - MY TRAINING - ALL
        """
        # get list
        response = self.client.get(
            '/api/v1/contents/my-lecture/to-do-list?show_deleted=0&offset=0&count=20&category_list=238,239,267,268,240,242,489,366,367,368,488,343,369,370,472,473,371,312,382,467,476,483,490,482,495,491,493,496,497&validity=1&company_key=26')

    @task
    def view_all_training_list(self):
        """
        TRAINING - ALL TRAINING
        """
        # get list
        response = self.client.get('/api/v1/user/all_user_list?company_key=26&user_status_list=ACTIVE')
        response = self.client.get('/api/v1/job-title/all-job-titles?company_key=26')
        response = self.client.get('/api/v1/contents/categories-from-dic?exclude_previous=1&company_key=26')
        response = self.client.get(
            '/api/v1/contents/lectures?show_deleted=0&offset=0&count=20&category_list=&exclude_previous=1&company_key=26')

    @task
    def view_user_management_group(self):
        """
        USER_MANAGEMENT - GROUP
        """
        # get list
        response = self.client.get('/api/v1/group/groups?show_deleted=0&company_key=26&by_requestor=0')

    @task
    def view_user_management_job_title(self):
        """
        USER_MANAGEMENT - JOB TITLE
        """
        # get list
        response = self.client.get('/api/v1/job-title/job-titles?show_deleted=0&offset=0&count=20&company_key=26')

    @task
    def view_user_management_user(self):
        """
        USER_MANAGEMENT - USER
        """
        # get list
        response = self.client.get('/api/v1/user/all_user_list?company_key=26&user_status_list=ACTIVE')
        response = self.client.get('/api/v1/job-title/all-job-titles?company_key=26')
        response = self.client.get('/api/v1/group/groups?show_deleted=0&company_key=26&by_requestor=0')

        response = self.client.get(
            '/api/v1/user/users?status=ACTIVE,INACTIVE&offset=0&count=20&roles=&group_list=&show_deleted=0&company_key=26')

    @task
    def view_contents_management_category(self):
        """
        CONTENTS MANAGEMENT - CATEGORY
        """
        # get list
        response = self.client.get('/api/v1/contents/categories?show_deleted=0&exclude_previous=0&company_key=26')

    @task
    def view_contents_management_lecture(self):
        """
        CONTENTS MANAGEMENT - LECTURE
        """
        # get list
        response = self.client.get('/api/v1/job-title/all-job-titles?company_key=26')
        response = self.client.get('/api/v1/user/all_user_list?company_key=26&user_status_list=ACTIVE')

        response = self.client.get(
            '/api/v1/contents/lectures?show_deleted=0&offset=0&count=20&category_list=&exclude_previous=1&type=LECTURE&company_key=26')

    @task
    def view_contents_management_quiz(self):
        """
        CONTENTS MANAGEMENT - QUIZ
        """
        # get list
        response = self.client.get(
            '/api/v1/contents/quizzes?show_deleted=0&offset=0&count=20&status=ACTIVE,+INACTIVE&company_key=26')

    @task
    def view_contents_management_course(self):
        """
        CONTENTS MANAGEMENT - COURSE
        """
        # get list
        response = self.client.get('/api/v1/job-title/all-job-titles?company_key=26')
        response = self.client.get('/api/v1/user/all_user_list?company_key=26&user_status_list=ACTIVE')
        response = self.client.get('/api/v1/contents/categories-from-dic?exclude_previous=1&company_key=26')
        response = self.client.get(
            '/api/v1/contents/lectures?show_deleted=0&offset=0&count=20&category_list=&exclude_previous=1&type=COURSE&company_key=26')

    @task
    def view_learning_progress_training(self):
        """
        LEARNING PROGRESS - TRAINING
        """
        # get list
        response = self.client.get('/api/v1/contents/categories-from-dic?company_key=26')
        response = self.client.get('/api/v1/progress/lectures?offset=0&count=20&category_list=&company_key=26')

    @task
    def view_learning_progress_user(self):
        """
        LEARNING PROGRESS - USER
        """
        # get list
        response = self.client.get('/api/v1/user/all_user_list_by_requester?company_key=26&user_status_list=ACTIVE')
        response = self.client.get('/api/v1/group/groups?show_deleted=0&company_key=26&by_requestor=1')
        response = self.client.get('/api/v1/contents/categories-from-dic?company_key=26')
        response = self.client.get(
            '/api/v1/progress/users?offset=0&count=20&show_deleted=0&category_list=&show_inactive_user=false&company_key=26')

    @task
    def view_system_management(self):
        """
        SYSTEM MANAGEMENT
        """
        response = self.client.get('/api/v1/sys/system?company_key=26')

    # 생성
    @task
    def add_category(self):
        """
        CONTENTS MANAGEMENT - CATEGORY - ADD
        """
        num1 = randint(0, 5000)
        num2 = randint(0, 5000)
        response = self.client.post('/api/v1/contents/categories', json={
            "parent_category_name": "NEW COMPANY 1",
            "parent_category_key": 0,
            "category_name": "test_category_" + str(num1) + "_" + str(num2),
            "note": None,
            "training_type": "MANDATORY",
            "due_days": None,
            "alarm": 0,
            "alarm_days": 0,
            "deleted": 0,
            "status": "ACTIVE",
            "trainee_list": [],
            "mandatory_trainee_list": [],
            "optional_trainee_list": [],
            "category_key": -1,
            "inactive_date": None,
            "will_inactive": 0,
            "name": "test_category_1",
            "company_key": 26
        })

    @task
    def add_lecture(self):
        """
        CONTENTS MANAGEMENT - LECTURE - ADD
        """
        num1 = randint(0, 5000)
        num2 = randint(0, 5000)
        response = self.client.post('/api/v1/contents/lectures', json={
            "category_key": 497,
            "name": "lecture_" + str(num1) + "_" + str(num2),
            "practitioner_type": None,
            "training_year": None,
            "note": None,
            "training_type": "MANDATORY",
            "lecture_length": 0,
            "active_date": "2021-10-20",
            "inactive_date": "9999-12-31",
            "due_date": None,
            "due_days": 1,
            "alarm": 0,
            "alarm_days": 0,
            "certificate": 0,
            "complete_date_mode": "AUTO_ASSIGN",
            "trainee_list": [
                {"trainee_key": 1013, "value": "dwlee", "trainee_type": "USER", "training_type": "MANDATORY"}],
            "mandatory_trainee_list": [
                {"trainee_key": 1013, "value": "dwlee", "trainee_type": "USER", "training_type": "MANDATORY"}],
            "optional_trainee_list": [], "include_contents": 0, "contents_type": None, "contents_name": None,
            "contents_url": None,
            "contents_link": "", "completion_period": 0, "visibility": False, "add_on_file_name": None,
            "add_on_file_url": None,
            "include_quiz": 0, "quiz_type": None, "quiz_key": None, "number_of_quiz": 0, "passing_score": 0,
            "start_date": None,
            "end_date": None, "has_quiz_time_limit": 0, "quiz_time_limit": 0, "company_key": 26
        })

참고 문헌


>> Home