Add SpawnFixture

This just turns spawn_n into a blocking passthrough so that we actually
run the spawned thing synchronously instead of not running it (and often
thinking we did).

Change-Id: I47ce83505361084e262843505031e3327d8e68a8
This commit is contained in:
Dan Smith 2015-05-04 12:09:54 -07:00
parent 1c292f3337
commit 90fb490aff
2 changed files with 26 additions and 0 deletions

View File

@ -402,3 +402,12 @@ class IndirectionAPIFixture(fixtures.Fixture):
self.orig_indirection_api = obj_base.NovaObject.indirection_api self.orig_indirection_api = obj_base.NovaObject.indirection_api
obj_base.NovaObject.indirection_api = self.indirection_api obj_base.NovaObject.indirection_api = self.indirection_api
self.addCleanup(self.cleanup) self.addCleanup(self.cleanup)
class SpawnIsSynchronousFixture(fixtures.Fixture):
"""Patch and restore the spawn_n utility method to be synchronous"""
def setUp(self):
super(SpawnIsSynchronousFixture, self).setUp()
self.useFixture(fixtures.MonkeyPatch(
'nova.utils.spawn_n', lambda f, *a, **k: f(*a, **k)))

View File

@ -17,6 +17,7 @@
import sys import sys
import fixtures as fx import fixtures as fx
import mock
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import uuidutils from oslo_utils import uuidutils
@ -26,6 +27,7 @@ from nova.db.sqlalchemy import api as session
from nova.objects import base as obj_base from nova.objects import base as obj_base
from nova.tests import fixtures from nova.tests import fixtures
from nova.tests.unit import conf_fixture from nova.tests.unit import conf_fixture
from nova import utils
CONF = cfg.CONF CONF = cfg.CONF
@ -292,3 +294,18 @@ class TestIndirectionAPIFixture(testtools.TestCase):
# ensure the initial value is restored # ensure the initial value is restored
self.assertIsNone(obj_base.NovaObject.indirection_api) self.assertIsNone(obj_base.NovaObject.indirection_api)
class TestSpawnIsSynchronousFixture(testtools.TestCase):
def test_spawn_patch(self):
orig_spawn = utils.spawn_n
fix = fixtures.SpawnIsSynchronousFixture()
self.useFixture(fix)
self.assertNotEqual(orig_spawn, utils.spawn_n)
def test_spawn_passes_through(self):
self.useFixture(fixtures.SpawnIsSynchronousFixture())
tester = mock.MagicMock()
utils.spawn_n(tester.function, 'foo', bar='bar')
tester.function.assert_called_once_with('foo', bar='bar')