]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- limit oracle DB reaps to identifiers generated from this
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Jun 2016 21:42:51 +0000 (17:42 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Jun 2016 21:45:16 +0000 (17:45 -0400)
run to prevent race conditions against concurrent runs

Change-Id: I065d1cec346ea7af03792c3cc2f30766f73c2bd3
(cherry picked from commit eb28ebb0f8a48ba57f68f21d64479b56bf689d24)

lib/sqlalchemy/testing/plugin/plugin_base.py
lib/sqlalchemy/testing/plugin/pytestplugin.py
lib/sqlalchemy/testing/provision.py
reap_oracle_dbs.py
tox_1_1.ini

index 1ba0a800f527a0053370fa19d2519c138f5e5fbe..cbe9f08dec4ff60223f84ecee199fa82fd88052c 100644 (file)
@@ -67,6 +67,9 @@ def setup_options(make_option):
                 dest="low_connections",
                 help="Use a low number of distinct connections - "
                 "i.e. for Oracle TNS")
+    make_option("--write-idents", type="string", dest="write_idents",
+                help="write out generated follower idents to <file>, "
+                "when -n<num> is used")
     make_option("--reversetop", action="store_true",
                 dest="reversetop", default=False,
                 help="Use a random-ordering set implementation in the ORM "
index 5bb6b966d557c39b865e70d8faf35b46ce6df03f..67ccb35508e459a3fb58e9fd2d88d09f4c8ae222 100644 (file)
@@ -9,7 +9,7 @@ import pytest
 import argparse
 import inspect
 import collections
-import itertools
+import os
 
 try:
     import xdist  # noqa
@@ -43,6 +43,14 @@ def pytest_configure(config):
             config.slaveinput["follower_ident"]
         )
 
+        if config.option.write_idents:
+            with open(config.option.write_idents, "a") as file_:
+                file_.write(config.slaveinput["follower_ident"] + "\n")
+    else:
+        if config.option.write_idents and \
+                os.path.exists(config.option.write_idents):
+            os.remove(config.option.write_idents)
+
     plugin_base.pre_begin(config.option)
 
     plugin_base.set_coverage_flag(bool(getattr(config.option,
index 4bba1be670c2c3e574b00b54eba1737051575e97..88d166981415662543cfd28af869ad12fd8cba7e 100644 (file)
@@ -40,7 +40,6 @@ class register(object):
 
 
 def create_follower_db(follower_ident):
-
     for cfg in _configs_for_db_operation():
         _create_db(cfg, cfg.db, follower_ident)
 
@@ -271,9 +270,14 @@ def _oracle_drop_db(cfg, eng, ident):
         _ora_drop_ignore(conn, "%s_ts2" % ident)
 
 
-def reap_oracle_dbs(eng):
+def reap_oracle_dbs(eng, idents_file):
     log.info("Reaping Oracle dbs...")
     with eng.connect() as conn:
+        with open(idents_file) as file_:
+            idents = set(line.strip() for line in file_)
+
+        log.info("identifiers in file: %s", ", ".join(idents))
+
         to_reap = conn.execute(
             "select u.username from all_users u where username "
             "like 'TEST_%' and not exists (select username "
@@ -283,7 +287,7 @@ def reap_oracle_dbs(eng):
         for name in all_names:
             if name.endswith("_ts1") or name.endswith("_ts2"):
                 continue
-            else:
+            elif name in idents:
                 to_drop.add(name)
                 if "%s_ts1" % name in all_names:
                     to_drop.add("%s_ts1" % name)
index ff638a01ed599568922dd2549aa9c5541173dd20..4762faac55afd41f118659ea4b0f9a90ce8dab16 100644 (file)
@@ -1,4 +1,4 @@
-"""Drop Oracle databases that are left over from a 
+"""Drop Oracle databases that are left over from a
 multiprocessing test run.
 
 Currently the cx_Oracle driver seems to sometimes not release a
@@ -10,6 +10,7 @@ from sqlalchemy.testing.plugin import plugin_base
 from sqlalchemy.testing import engines
 from sqlalchemy.testing import provision
 import logging
+import sys
 
 logging.basicConfig()
 logging.getLogger(provision.__name__).setLevel(logging.INFO)
@@ -19,6 +20,6 @@ oracle = plugin_base.file_config.get('db', 'oracle')
 from sqlalchemy.testing import provision
 
 engine = engines.testing_engine(oracle, {})
-provision.reap_oracle_dbs(engine)
+provision.reap_oracle_dbs(engine, sys.argv[1])
 
 
index d5c3b670b146f29bc812f1ea260ba9fb4d79f6af..3c577eb0de7cb30493a3f0c7a7110f60e3984e93 100644 (file)
@@ -52,7 +52,7 @@ setenv=
     sqlite: SQLITE=--db sqlite
     postgresql: POSTGRESQL=--db postgresql
     mysql: MYSQL=--db mysql --db pymysql
-    oracle: ORACLE=--db oracle --low-connections
+    oracle: ORACLE=--db oracle --low-connections --write-idents oracle_idents.txt
     mssql: MSSQL=--db pyodbc --db pymssql
     backendonly: BACKENDONLY=--backend-only
 
@@ -65,7 +65,7 @@ passenv=ORACLE_HOME NLS_LANG
 commands=
   {nocext}: sh -c "rm -f lib/sqlalchemy/*.so"
   {env:BASECOMMAND} {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:BACKENDONLY:} {env:COVERAGE:} {posargs}
-  {oracle}: python reap_oracle_dbs.py
+  {oracle}: python reap_oracle_dbs.py oracle_idents.txt
 
 
 [testenv:pep8]