본문 바로가기

성능테스트/Locust

[ Locust ] Locust 사용법(windows)

반응형

1. python 3.6버젼 이상 설치

 

2. locust 설치

python -m pip install locust

설치확인 

locust --version

3. locust 실행

locust를 실행할 경로에 locustfile.py파일 생성

import time,re,urllib3
from locust import HttpUser, task, between, TaskSet, SequentialTaskSet

class SequenceOfTasks(SequentialTaskSet):
    wait_time = between(1, 1)
    #session_text = ''


class QuickstartUser(HttpUser):
    wait_time = between(1, 1)

    def on_start(self):
        # 로그인시 https url(https://g-yangsan.gen.es.kr:451/login.php)이 호출되는데 실제 ssl인증서를 통한 로그인이 아니여서 self.client.proxies 세팅을 "https":"http://localhost:8887"로 했을때
        # fiddler에 display가 정상적으로 되었음.
        #self.client.proxies = {"http": "http://localhost:8887", "https": "https://localhost:8887"}
        #self.client.proxies = {"http": "http://localhost:8887"}
        #self.client.proxies = {"https": "http://localhost:8887"}
        #self.client.verify = False

        response = self.client.get("/")
        print(response.headers["Set-Cookie"])
        # print(response.content)
        # print(response.text)
        p = re.compile('SESSIONID=(.+?);')
        session = p.search(response.headers["Set-Cookie"]).group(1)
        print(session)
        self.session_text = 'SESSIONID=' + session
        print(self.session_text)

        print(self.session_text)
        self.client.headers.update({'Cookie': self.session_text})
        response = self.client.get("/login.php?id=81")
        p = re.compile('csrf_token" value="(.+?)"')
        self.token = p.search(response.text).group(1)
        urllib3.disable_warnings()
        print(self.token)

        self.client.headers.update({'Cookie': self.session_text})
        self.client.headers.update({'Referer': 'http://g-yangsan.gen.es.kr/login.php?id=81'})
        response = self.client.post("https://g-yangsan.gen.es.kr:451/login.php", {'mode': 'login', 'id': '81','path':'','csrf_token':self.token,'userid':'vlfdus99','passwd':'!a5711327'})

    @task
    def mypage(self):
        self.client.headers.update({'Cookie': self.session_text})
        self.client.headers.update({'Referer': 'http://g-yangsan.gen.es.kr/login.php?id=81'})
        response = self.client.get("/join.php?id=88&mode=info")
        print(response.headers)
        print(response.text)


locust 실행

locust

4. locust web 접속

http://localhost:8089

5. locust web 모니터링

 

6. 참고 url

locust 설치
https://bcho.tistory.com/1369
https://dejavuqa.tistory.com/131

locust 스크립트 작성
https://bcho.tistory.com/1369
https://pko89403.github.io/post/locust/
https://gist.github.com/agconti/0f3886cbf1ce158e913e
https://loadforge.com/directory/custom_headers ->custom header
https://stackoverflow.com/questions/61132424/locust-tasksequence-problem-with-more-than-1-seq-task -> tasksequence
https://github.com/locustio/locust/issues/150 -> multi host
https://docs.djangoproject.com/en/4.0/topics/testing/tools/ -> post
https://stackoverflow.com/questions/59085387/is-there-any-way-where-i-can-send-host-value-as-a-parameter-in-locust -> header setting
https://github.com/QAInsights/Learn-Locust-Series/blob/main/DataParameterization/parameterization.py -> csv parameter
https://github.com/QAInsights/Learn-Locust-Series/blob/main/DistributedLoadTesting/petstore.py -> sample site

반응형

'성능테스트 > Locust' 카테고리의 다른 글

Running a distributed load test on Kubernetes  (0) 2023.01.25