# HG changeset patch # User Boris Feld <boris.feld@octobus.net> # Date 1511819175 18000 # Mon Nov 27 16:46:15 2017 -0500 # Node ID 2e74034c61404b25bb3591db6377b6c3a65861e0 # Parent 6c47cf2d5a65674a094ca633a8436cd672bd23f0 More cleaning and refactoring. Extract the common variants in a separate class. Also forces the benchmarks to run in a clean environment. diff --git a/benchmarks/basic_commands.py b/benchmarks/basic_commands.py --- a/benchmarks/basic_commands.py +++ b/benchmarks/basic_commands.py @@ -3,14 +3,15 @@ import time import timeit -from .utils import REPOS, BaseTrackTestSuite, BaseTimeTestSuite, median +from .utils import (BaseNChangesetsTestSuite, BaseTimeTestSuite, + BaseTrackTestSuite, median) class TestSuite(BaseTrackTestSuite): timeout = 120 - def track_commit(self, repo_name): + def track_commit(self, *args, **kwargs): timings = [] args = ["-A", "-m", "My commit message", "-u", "<test@octobus.net>"] @@ -88,10 +89,8 @@ return time -class LogTimeTestSuite(BaseTimeTestSuite): +class LogTimeTestSuite(BaseNChangesetsTestSuite): - params = [REPOS, [10, 100, 1000, 10000]] - param_names = ["repo", "changesets"] timeout = 300 def __init__(self): @@ -104,10 +103,8 @@ self._execute("log", "-r", "tip~%d::" % n) -class UpdateTimeTestSuite(BaseTimeTestSuite): +class UpdateTimeTestSuite(BaseNChangesetsTestSuite): - params = [REPOS, [10, 100, 1000, 10000]] - param_names = ["repo", "changesets"] timeout = 500 def __init__(self): @@ -121,10 +118,8 @@ self._execute("up", "-r", "tip") -class BundleTimeTestSuite(BaseTimeTestSuite): +class BundleTimeTestSuite(BaseNChangesetsTestSuite): - params = [REPOS, [10, 100, 1000, 10000]] - param_names = ["repo", "changesets"] timeout = 500 def __init__(self): diff --git a/benchmarks/utils.py b/benchmarks/utils.py --- a/benchmarks/utils.py +++ b/benchmarks/utils.py @@ -148,13 +148,14 @@ self.hgpath = os.path.join(venv, "bin", "hg") self.repo_path = os.path.join(REPOS_DIR, self.repo_name) + # Use a clean environ to run command + self.environ = {} + class BaseTrackTestSuite(BaseTestSuite): def _execute(self, command, *args): cmd = self._prepare_cmd(command, *args) - # Clean environ - os.environ = {} timings = [] @@ -182,7 +183,8 @@ def _single_execute(self, cmd): try: before = time.time() - subprocess.check_output(cmd, stderr=subprocess.STDOUT) + subprocess.check_output(cmd, stderr=subprocess.STDOUT, + env=self.environ) after = time.time() return after - before except subprocess.CalledProcessError as e: @@ -212,4 +214,11 @@ return cmd def _single_execute(self, cmd): - return subprocess.check_output(cmd, stderr=subprocess.STDOUT) + return subprocess.check_output(cmd, stderr=subprocess.STDOUT, + env=self.environ) + + +class BaseNChangesetsTestSuite(BaseTimeTestSuite): + + params = [REPOS, [10, 100, 1000, 10000]] + param_names = ["repo", "changesets"]