svn_locust.py #1

  • //
  • guest/
  • robert_cowham/
  • p4benchmark/
  • main/
  • svn_locust.py
  • View
  • Commits
  • Open Download .zip Download (2 KB)
import time
import os
from locust import Locust, events, task, TaskSet
import RepoBenchmark

startdir = os.getcwd()

class SvnRepoTestClient(object):
    """
    Simple, sample client implementation that calls p4/svn commands and
    fires locust events on request_success and request_failure, so that all requests
    gets tracked in locust's statistics.
    """
    def __init__(self):
        pass

    def do_work(self, config):
        request_type = "repo_tasks"
        name = "svn"
        start_time = time.time()
        try:
            rb = RepoBenchmark.SvnBenchmark(startdir, config)
            rb.run()
        except Exception as e:
            total_time = int((time.time() - start_time) * 1000)
            events.request_failure.fire(request_type=request_type, name=name, response_time=total_time, exception=e)
        else:
            total_time = int((time.time() - start_time) * 1000)
            events.request_success.fire(request_type=request_type, name=name, response_time=total_time, response_length=0)

class SvnRepoTestLocust(Locust):
    """
    This is the abstract Locust class which should be subclassed. It provides RepoTest client
    that can be used to make requests that will be tracked in Locust's statistics.
    """
    def __init__(self, *args, **kwargs):
        super(SvnRepoTestLocust, self).__init__(*args, **kwargs)
        self.client = SvnRepoTestClient()


class SvnRepoUser(SvnRepoTestLocust):

    min_wait = 1000
    max_wait = 10000

    def __init__(self, *args, **kwargs):
        super(SvnRepoUser, self).__init__(*args, **kwargs)
        self.config = RepoBenchmark.readConfig(startdir)
        self.min_wait = self.config["general"]["min_wait"]
        self.max_wait = self.config["general"]["max_wait"]

    class task_set(TaskSet):
        @task(10)
        def do_work(self):
            self.client.do_work(RepoBenchmark.readConfig(startdir))
# Change User Description Committed
#4 24711 Robert Cowham Restructure and tidy up
#3 19799 Robert Cowham Refactored to put some common stuff in RepoLocust.py
#2 19798 Robert Cowham Log exceptions.
Refactor Svn as well
#1 19773 Robert Cowham Initial version of benchmark scripts