# -*- coding: utf-8 -*-
# 性能测试类
# 作者: 陈磊
# 时间: 2019-10-21


from WorkUtils.UtilsLog import UtilsLog
from locust import HttpLocust, TaskSet, task

import subprocess


log = UtilsLog()


class BaseTask(TaskSet):

    def on_start(self):
        log.info(self.__doc__)

    @task(1)
    def base_post(self, url, param, json):
        """
        :param url:
        :param param:
        :param json:
        :return:
        """
        response = self.client.post(
            url=url,
            params=param,
            json=json
        )
        if response.status_code != 200:
            log.info("返回状态码异常")
            log.info("返回状态码:%s" % response.status_code)
            print("")
            print()
        elif response.status_code == 200:
            log.info("返回状态码正常")


class MobileUserLocust(HttpLocust):
    u"""
    min_wait ：用户执行任务之间等待时间的下界，单位：毫秒。
    max_wait ：用户执行任务之间等待时间的上界，单位：毫秒。
    """
    # weight = 3
    task_set = BaseTask.base_post(url="/", param={}, json={})
    host = "http://www.baidu.com"
    min_wait = 3000
    max_wait = 6000


if __name__ == "__main__":
    subprocess.Popen("locust -f UtilsLocust.py", shell=True)