diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-10-24 10:11:12 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-10-24 13:45:50 -0400 |
commit | 5b36e169ea74d2345545169124c31cdb6c319408 (patch) | |
tree | 776025d85f3b33fafbb36cb9f47bd7ea44335a1a /oslo_db/tests | |
parent | baa0a045b51fd261fdcef6f7dfafe8e823f26e7a (diff) | |
download | oslo-db-5b36e169ea74d2345545169124c31cdb6c319408.tar.gz |
Add "is_started" flag to enginefacade
Some module reloading scenarios such as that which occurs
within mod_wsgi mean that an existing module-level enginefacade
is already in the "started" state, however initialization
routines from the calling application may still attempt to
call the ``.configure`` method. Add a new flag is_started
to both _TransactionContextManager and _TransactionFactory so
that calling code can check for this state ahead of time;
additionally, promote the TypeError raised to a specific subclass
enginefacade.AlreadyStartedError to allow for better optimistic
schemes.
Change-Id: I2f5a9e35c2fae0c28b78beef3dcd2c4794362766
References: I704196711d30c1124e713ac31111a8ea6fa2f1ba
Diffstat (limited to 'oslo_db/tests')
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_enginefacade.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py index cab7547..b29a122 100644 --- a/oslo_db/tests/sqlalchemy/test_enginefacade.py +++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py @@ -479,6 +479,32 @@ class MockFacadeTest(oslo_test_base.BaseTestCase): [mock.call.dispose()] ) + def test_started_flag(self): + facade = enginefacade.transaction_context() + + self.assertFalse(facade.is_started) + facade.configure(connection=self.engine_uri) + facade.writer.get_engine() + + self.assertTrue(facade.is_started) + + def test_started_exception(self): + facade = enginefacade.transaction_context() + + self.assertFalse(facade.is_started) + facade.configure(connection=self.engine_uri) + facade.writer.get_engine() + + exc = self.assertRaises( + enginefacade.AlreadyStartedError, + facade.configure, + connection=self.engine_uri + ) + self.assertEqual( + "this TransactionFactory is already started", + exc.args[0] + ) + def test_session_reader_decorator(self): context = oslo_context.RequestContext() |