summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-02-09 21:08:21 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2016-02-09 21:09:06 -0500
commitd802bcb8dfbad38cb7fa5b62c52a6a5a509d2c33 (patch)
treea62d59fce9b54b98e477c4fb24670ef43503dfbf /lib
parent9a156c586ddf339acd7df1dda7a790f5573ada51 (diff)
downloadsqlalchemy-d802bcb8dfbad38cb7fa5b62c52a6a5a509d2c33.tar.gz
- don't drop the ts1/ts2 databases without seeing the primary DB,
because we never log in on the ts1/ts2. races against other runs and erases their DBs (cherry picked from commit 3f1f1895ac99963da1a989c69c2dce59ae916ffc)
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/testing/provision.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py
index f09bb715c..2797411c7 100644
--- a/lib/sqlalchemy/testing/provision.py
+++ b/lib/sqlalchemy/testing/provision.py
@@ -266,6 +266,7 @@ def _ora_drop_ignore(conn, dbname):
log.warn("couldn't drop db: %s" % err)
return False
+
@_drop_db.for_db("oracle")
def _oracle_drop_db(cfg, eng, ident):
with eng.connect() as conn:
@@ -278,18 +279,32 @@ def _oracle_drop_db(cfg, eng, ident):
_ora_drop_ignore(conn, "%s_ts1" % ident)
_ora_drop_ignore(conn, "%s_ts2" % ident)
+
def reap_oracle_dbs(eng):
log.info("Reaping Oracle dbs...")
with eng.connect() as conn:
to_reap = conn.execute(
- "select u.username from all_users u where username "
- "like 'TEST_%' and not exists (select username "
- "from v$session where username=u.username)")
- dropped = 0
- for total, (username, ) in enumerate(to_reap, 1):
+ "select u.username from all_users u where username "
+ "like 'TEST_%' and not exists (select username "
+ "from v$session where username=u.username)")
+ all_names = set([username.lower() for (username, ) in to_reap])
+ to_drop = set()
+ for name in all_names:
+ if name.endswith("_ts1") or name.endswith("_ts2"):
+ continue
+ else:
+ to_drop.add(name)
+ if "%s_ts1" % name in all_names:
+ to_drop.add("%s_ts1" % name)
+ if "%s_ts2" % name in all_names:
+ to_drop.add("%s_ts2" % name)
+
+ dropped = total = 0
+ for total, username in enumerate(to_drop, 1):
if _ora_drop_ignore(conn, username):
dropped += 1
- log.info("Dropped %d out of %d stale databases detected", dropped, total)
+ log.info(
+ "Dropped %d out of %d stale databases detected", dropped, total)
@_follower_url_from_main.for_db("oracle")