Skip to content

Commit eb28ebb

Browse files
committed
- limit oracle DB reaps to identifiers generated from this
run to prevent race conditions against concurrent runs Change-Id: I065d1cec346ea7af03792c3cc2f30766f73c2bd3
1 parent dc9e35f commit eb28ebb

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

lib/sqlalchemy/testing/plugin/plugin_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def setup_options(make_option):
6767
dest="low_connections",
6868
help="Use a low number of distinct connections - "
6969
"i.e. for Oracle TNS")
70+
make_option("--write-idents", type="string", dest="write_idents",
71+
help="write out generated follower idents to <file>, "
72+
"when -n<num> is used")
7073
make_option("--reversetop", action="store_true",
7174
dest="reversetop", default=False,
7275
help="Use a random-ordering set implementation in the ORM "

lib/sqlalchemy/testing/plugin/pytestplugin.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import argparse
1010
import inspect
1111
import collections
12-
import itertools
12+
import os
1313

1414
try:
1515
import xdist # noqa
@@ -43,6 +43,14 @@ def pytest_configure(config):
4343
config.slaveinput["follower_ident"]
4444
)
4545

46+
if config.option.write_idents:
47+
with open(config.option.write_idents, "a") as file_:
48+
file_.write(config.slaveinput["follower_ident"] + "\n")
49+
else:
50+
if config.option.write_idents and \
51+
os.path.exists(config.option.write_idents):
52+
os.remove(config.option.write_idents)
53+
4654
plugin_base.pre_begin(config.option)
4755

4856
plugin_base.set_coverage_flag(bool(getattr(config.option,
@@ -58,6 +66,7 @@ def pytest_sessionstart(session):
5866
def pytest_sessionfinish(session):
5967
plugin_base.final_process_cleanup()
6068

69+
6170
if has_xdist:
6271
import uuid
6372

lib/sqlalchemy/testing/provision.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def __call__(self, cfg, *arg):
4040

4141

4242
def create_follower_db(follower_ident):
43-
4443
for cfg in _configs_for_db_operation():
4544
_create_db(cfg, cfg.db, follower_ident)
4645

@@ -271,9 +270,14 @@ def _oracle_drop_db(cfg, eng, ident):
271270
_ora_drop_ignore(conn, "%s_ts2" % ident)
272271

273272

274-
def reap_oracle_dbs(eng):
273+
def reap_oracle_dbs(eng, idents_file):
275274
log.info("Reaping Oracle dbs...")
276275
with eng.connect() as conn:
276+
with open(idents_file) as file_:
277+
idents = set(line.strip() for line in file_)
278+
279+
log.info("identifiers in file: %s", ", ".join(idents))
280+
277281
to_reap = conn.execute(
278282
"select u.username from all_users u where username "
279283
"like 'TEST_%' and not exists (select username "
@@ -283,7 +287,7 @@ def reap_oracle_dbs(eng):
283287
for name in all_names:
284288
if name.endswith("_ts1") or name.endswith("_ts2"):
285289
continue
286-
else:
290+
elif name in idents:
287291
to_drop.add(name)
288292
if "%s_ts1" % name in all_names:
289293
to_drop.add("%s_ts1" % name)

reap_oracle_dbs.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Drop Oracle databases that are left over from a
1+
"""Drop Oracle databases that are left over from a
22
multiprocessing test run.
33
44
Currently the cx_Oracle driver seems to sometimes not release a
@@ -10,6 +10,7 @@
1010
from sqlalchemy.testing import engines
1111
from sqlalchemy.testing import provision
1212
import logging
13+
import sys
1314

1415
logging.basicConfig()
1516
logging.getLogger(provision.__name__).setLevel(logging.INFO)
@@ -19,6 +20,6 @@
1920
from sqlalchemy.testing import provision
2021

2122
engine = engines.testing_engine(oracle, {})
22-
provision.reap_oracle_dbs(engine)
23+
provision.reap_oracle_dbs(engine, sys.argv[1])
2324

2425

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ setenv=
5252
sqlite: SQLITE=--db sqlite
5353
postgresql: POSTGRESQL=--db postgresql
5454
mysql: MYSQL=--db mysql --db pymysql
55-
oracle: ORACLE=--db oracle --low-connections
55+
oracle: ORACLE=--db oracle --low-connections --write-idents oracle_idents.txt
5656
mssql: MSSQL=--db pyodbc --db pymssql
5757
backendonly: BACKENDONLY=--backend-only
5858

@@ -65,7 +65,7 @@ passenv=ORACLE_HOME NLS_LANG
6565
commands=
6666
{nocext}: sh -c "rm -f lib/sqlalchemy/*.so"
6767
{env:BASECOMMAND} {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:BACKENDONLY:} {env:COVERAGE:} {posargs}
68-
{oracle}: python reap_oracle_dbs.py
68+
{oracle}: python reap_oracle_dbs.py oracle_idents.txt
6969

7070

7171
[testenv:pep8]

0 commit comments

Comments
 (0)