# HG changeset patch
# User Philippe Pepiot <philippe.pepiot@logilab.fr>
# Date 1528790028 -7200
#      Tue Jun 12 09:53:48 2018 +0200
# Node ID 49aa5eec015c270c396d80b230dba7b8a15f469c
# Parent  dbf6c2ca5ed8d55f176e070bd953571d9f6d8cd1
Handle params "repo_type" and "revset" Mixin class

In following changesets we will add exchanges benchmarks not using "strip" or
"revset" params.

Moving this outside of the BaseExchangeTimeSuite allow to re-use this logic
without inheriting from it.

diff --git a/benchmarks/basic_commands.py b/benchmarks/basic_commands.py
--- a/benchmarks/basic_commands.py
+++ b/benchmarks/basic_commands.py
@@ -233,14 +233,7 @@
         self.thread.join()
 
 
-class BaseExchangeTimeSuite(BaseTestSuite):
-    param_names = BaseTestSuite.param_names + [
-        'repo_type', 'strip', 'revset']
-    params = BaseTestSuite.params + [
-        ['local', 'ssh', 'http'],
-        get_strip_variants(),
-        [None, 'tip']]
-    timeout = 1800
+class BaseExchangeMixin(object):
 
     def _remote_path_cmd(self, path):
         if self.repo_type == 'local':
@@ -265,6 +258,36 @@
         else:
             raise NotImplementedError
 
+    def _setup_repo_type(self, repo_type):
+        self._hgserve = None
+        if repo_type == 'http' and self.get_asv_rev() in self.get_skip()['hgweb']:
+            raise NotImplementedError
+        self.repo_type = repo_type
+        if repo_type == 'http':
+            self._hgserve = HgWeb()
+            self.hgport = self._hgserve.start(self.hgpath, self.environ)
+
+    def _teardown_repo_type(self):
+        if self._hgserve is not None:
+            self._hgserve.stop()
+            self._hgserve = None
+
+    def _setup_revset(self, revset):
+        if revset is not None:
+            self.rev = self.hg('identify', '-i', '-r', revset).strip()
+        else:
+            self.rev = None
+
+
+class BaseExchangeTimeSuite(BaseExchangeMixin, BaseTestSuite):
+    param_names = BaseTestSuite.param_names + [
+        'repo_type', 'strip', 'revset']
+    params = BaseTestSuite.params + [
+        ['local', 'ssh', 'http'],
+        get_strip_variants(),
+        [None, 'tip']]
+    timeout = 1800
+
     def run(self, local_repo, command, remote_repo, expected_return_code=None):
         if not isinstance(command, (list, tuple)):
             command = [command]
@@ -276,27 +299,20 @@
             expected_return_code = 1 if self.strip == "same" else 0
         self.hg(*cmd, expected_return_code=expected_return_code)
 
-    def setup(self, repo_name, repo_type, strip, revset):
-        super(BaseExchangeTimeSuite, self).setup(repo_name)
-        self._hgserve = None
-        if repo_type == 'http' and self.get_asv_rev() in self.get_skip()['hgweb']:
-            raise NotImplementedError
+    def setup(self, *args):
+        args = list(args)
+        revset = args.pop(-1)
+        self.strip = args.pop(-1)
+        repo_type = args.pop(-1)
+        super(BaseExchangeTimeSuite, self).setup(*args)
+        self._setup_repo_type(repo_type)
+        self._setup_revset(revset)
         repo_suffix = urllib.quote_plus(strip)
         self.clone_path = os.path.join(REPOS_DIR, '.cache', '{}-partial-{}'.format(
             repo_name, repo_suffix))
-        if revset is not None:
-            self.rev = self.hg('identify', '-i', '-r', revset).strip()
-        else:
-            self.rev = None
-        self.strip = strip
-        self.repo_type = repo_type
-        if repo_type == 'http':
-            self._hgserve = HgWeb()
-            self.hgport = self._hgserve.start(self.hgpath, self.environ)
 
     def teardown(self, *args, **kwargs):
-        if self._hgserve is not None:
-            self._hgserve.stop()
+        self._teardown_repo_type()
 
 
 class ExchangeTimeSuite(BaseExchangeTimeSuite):