import math
from locust import FastHttpUser,task,LoadTestShape


class AdServerUser(FastHttpUser):
    @task
    def request_1(self):
        self.client.get("/AdServer/AdServerServlet?pubId=15921&siteId=577068&adId=2120716&kadfloor=11.0&devicetype=0&operId=102&adtype=3&keywords=adt%3A3_protocol%3A2_c%3A23098%3B22926%3B23223_p%3A11_wh%3A320x50&kadwidth=320&kadheight=50&wakanda=5555&kadpageurl=abc.com")


class StepLoadShape(LoadTestShape):
    """
    A step load shape
    Keyword arguments:
        step_time -- Time between steps
        step_load -- User increase amount at each step
        spawn_rate -- Users to stop/start per second at every step
        time_limit -- Time limit in seconds
    """

    step_time = 30
    step_load = 10
    spawn_rate = 10
    time_limit = 600

    def tick(self):
        run_time = self.get_run_time()

        if run_time > self.time_limit:
            return None

        current_step = math.floor(run_time / self.step_time) + 1
        return (current_step * self.step_load, self.spawn_rate)
