]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add option for "sparse" backend tests and apply to memusage
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jun 2019 21:18:59 +0000 (17:18 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 20 Jun 2019 22:09:37 +0000 (18:09 -0400)
The memusage tests are extremely time and memory intensive,
and when CI runs against MySQL or Postgresql there are many
database/driver combinations for which the "backend" tests
repeatedly run; as these tests are more oriented towards
basic dialect interaction, add a new "sparse" backend option
that will run the tests only once per base dialect.

Change-Id: I312aa0332d7ec1ff4e2faa15f6b189d6f0f68393
(cherry picked from commit 0ad64da3971bd4ac42699cf891fd689e7291cd2f)

lib/sqlalchemy/testing/plugin/plugin_base.py
test/aaa_profiling/test_memusage.py

index ef44a5906bc7ace2982cf2531c622bab913126cd..8f79b416314745639ffa1eda90e30ac2b704b19e 100644 (file)
@@ -93,7 +93,7 @@ def setup_options(make_option):
         "--backend-only",
         action="store_true",
         dest="backend_only",
-        help="Run only tests marked with __backend__",
+        help="Run only tests marked with __backend__ or __sparse_backend__",
     )
     make_option(
         "--nomemory",
@@ -483,8 +483,10 @@ def want_class(cls):
         return False
     elif cls.__name__.startswith("_"):
         return False
-    elif config.options.backend_only and not getattr(
-        cls, "__backend__", False
+    elif (
+        config.options.backend_only
+        and not getattr(cls, "__backend__", False)
+        and not getattr(cls, "__sparse_backend__", False)
     ):
         return False
     else:
@@ -519,8 +521,11 @@ def want_method(cls, fn):
 
 
 def generate_sub_tests(cls, module):
-    if getattr(cls, "__backend__", False):
-        for cfg in _possible_configs_for_cls(cls):
+    if getattr(cls, "__backend__", False) or getattr(
+        cls, "__sparse_backend__", False
+    ):
+        sparse = getattr(cls, "__sparse_backend__", False)
+        for cfg in _possible_configs_for_cls(cls, sparse=sparse):
             orig_name = cls.__name__
 
             # we can have special chars in these names except for the
@@ -589,7 +594,7 @@ def after_test(test):
     engines.testing_reaper._after_test_ctx()
 
 
-def _possible_configs_for_cls(cls, reasons=None):
+def _possible_configs_for_cls(cls, reasons=None, sparse=False):
     all_configs = set(config.Config.all_configs())
 
     if cls.__unsupported_on__:
@@ -632,6 +637,25 @@ def _possible_configs_for_cls(cls, reasons=None):
         if all_configs.difference(non_preferred):
             all_configs.difference_update(non_preferred)
 
+    if sparse:
+        # pick only one config from each base dialect
+        # sorted so we get the same backend each time selecting the highest
+        # server version info.
+        per_dialect = {}
+        for cfg in reversed(
+            sorted(
+                all_configs,
+                key=lambda cfg: (
+                    cfg.db.name,
+                    cfg.db.dialect.server_version_info,
+                ),
+            )
+        ):
+            db = cfg.db.name
+            if db not in per_dialect:
+                per_dialect[db] = cfg
+        return per_dialect.values()
+
     return all_configs
 
 
index 8e7bd57bb499689a1eb58d2f61c53fc89f189a62..d1e9387ff4f187317caef925c81173723fb42354 100644 (file)
@@ -264,7 +264,7 @@ class MemUsageWBackendTest(EnsureZeroed):
 
     __tags__ = ("memory_intensive",)
     __requires__ = "cpython", "memory_process_intensive"
-    __backend__ = True
+    __sparse_backend__ = True
 
     # ensure a pure growing test trips the assertion
     @testing.fails_if(lambda: True)