Merge "fix usage of opportunistic test cases with enginefacade"
This commit is contained in:
commit
36a4fe61a7
@ -23,6 +23,7 @@ import warnings
|
||||
|
||||
import fixtures
|
||||
from oslo_config import cfg
|
||||
from oslo_db.sqlalchemy import enginefacade
|
||||
from oslo_messaging import conffixture as messaging_conffixture
|
||||
import six
|
||||
|
||||
@ -476,3 +477,39 @@ class StableObjectJsonFixture(fixtures.Fixture):
|
||||
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.objects.base.NovaObject.obj_to_primitive', _doit))
|
||||
|
||||
|
||||
class EngineFacadeFixture(fixtures.Fixture):
|
||||
"""Fixture to isolation EngineFacade during tests.
|
||||
|
||||
Because many elements of EngineFacade are based on globals, once
|
||||
an engine facade has been initialized, all future code goes
|
||||
through it. This means that the initialization of sqlite in
|
||||
databases in our Database fixture will drive all connections to
|
||||
sqlite. While that's fine in a production environment, during
|
||||
testing this means we can't test againts multiple backends in the
|
||||
same test run.
|
||||
|
||||
oslo.db does not yet support a reset mechanism here. This builds a
|
||||
custom in tree engine facade fixture to handle this. Eventually
|
||||
this will be added to oslo.db and this can be removed. Tracked by
|
||||
https://bugs.launchpad.net/oslo.db/+bug/1548960
|
||||
|
||||
"""
|
||||
def __init__(self, ctx_manager, engine, sessionmaker):
|
||||
super(EngineFacadeFixture, self).__init__()
|
||||
self._ctx_manager = ctx_manager
|
||||
self._engine = engine
|
||||
self._sessionmaker = sessionmaker
|
||||
|
||||
def setUp(self):
|
||||
super(EngineFacadeFixture, self).setUp()
|
||||
|
||||
self._existing_factory = self._ctx_manager._root_factory
|
||||
self._ctx_manager._root_factory = enginefacade._TestTransactionFactory(
|
||||
self._engine, self._sessionmaker, apply_global=False,
|
||||
synchronous_reader=True)
|
||||
self.addCleanup(self.cleanup)
|
||||
|
||||
def cleanup(self):
|
||||
self._ctx_manager._root_factory = self._existing_factory
|
||||
|
Loading…
x
Reference in New Issue
Block a user