diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-22 13:12:43 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-08-22 13:25:58 -0400 |
commit | 35e879fcded5b21e70d6de840532187f5d304b46 (patch) | |
tree | d03d45b50dc48e63169baded80987b856c49fd3f | |
parent | a1d78a2ce8063e4b0fa351001f56fba06d44b8ce (diff) | |
download | sqlalchemy-35e879fcded5b21e70d6de840532187f5d304b46.tar.gz |
- allow a separate template database to be used for
PG CREATE DATABASE. as nobody will connect to it that would
solve the contention issue here
- backport --nomemory since tox.ini is using it
Change-Id: I00a4d52091876e120faff4a8a5493c53280d96f1
(cherry picked from commit 4c306818396c8cc98a16a14c5ed3361cf6ff373a)
-rw-r--r-- | lib/sqlalchemy/testing/plugin/plugin_base.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/provision.py | 13 |
2 files changed, 19 insertions, 5 deletions
diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py index 860303882..18f5e0357 100644 --- a/lib/sqlalchemy/testing/plugin/plugin_base.py +++ b/lib/sqlalchemy/testing/plugin/plugin_base.py @@ -63,6 +63,11 @@ def setup_options(make_option): help="Drop all tables in the target database first") make_option("--backend-only", action="store_true", dest="backend_only", help="Run only tests marked with __backend__") + make_option("--nomemory", action="store_true", dest="nomemory", + help="Don't run memory profiling tests") + make_option("--postgresql-templatedb", type="string", + help="name of template database to use for Postgresql " + "CREATE DATABASE (defaults to current database)") make_option("--low-connections", action="store_true", dest="low_connections", help="Use a low number of distinct connections - " @@ -229,6 +234,12 @@ def _setup_options(opt, file_config): @pre +def _set_nomemory(opt, file_config): + if opt.nomemory: + exclude_tags.add("memory_intensive") + + +@pre def _monkeypatch_cdecimal(options, file_config): if options.cdecimal: import cdecimal diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py index f62024084..125479d31 100644 --- a/lib/sqlalchemy/testing/provision.py +++ b/lib/sqlalchemy/testing/provision.py @@ -159,23 +159,26 @@ def _sqlite_post_configure_engine(url, engine, follower_ident): @_create_db.for_db("postgresql") def _pg_create_db(cfg, eng, ident): + template_db = cfg.options.postgresql_templatedb + with eng.connect().execution_options( isolation_level="AUTOCOMMIT") as conn: try: _pg_drop_db(cfg, conn, ident) except Exception: pass - currentdb = conn.scalar("select current_database()") - for attempt in range(10): + if not template_db: + template_db = conn.scalar("select current_database()") + for attempt in range(3): try: conn.execute( - "CREATE DATABASE %s TEMPLATE %s" % (ident, currentdb)) + "CREATE DATABASE %s TEMPLATE %s" % (ident, template_db)) except exc.OperationalError as err: if "accessed by other users" in str(err): log.info( "Waiting to create %s, URI %r, " - "template DB is in use sleeping for .5", - ident, eng.url) + "template DB %s is in use sleeping for .5", + ident, eng.url, template_db) time.sleep(.5) else: break |