summaryrefslogtreecommitdiff
path: root/nova/tests/unit/test_fixtures.py
diff options
context:
space:
mode:
authorAndrew Laski <andrew@lascii.com>2016-03-09 14:04:36 -0500
committerAndrew Laski <andrew@lascii.com>2016-03-10 13:48:41 -0500
commit61fc1b9ee11e416aecbf3a29e1d150a53fc890e8 (patch)
tree00a03bc534b7b661e98f2fd7de89b9abc8675e14 /nova/tests/unit/test_fixtures.py
parent59c9e57ecb0edf4e952e1d58782c9c75e7b329ad (diff)
downloadnova-61fc1b9ee11e416aecbf3a29e1d150a53fc890e8.tar.gz
Change SpawnIsSynchronous fixture return
In normal usage utils.spawn returns an eventlet.greenthread.GreenThread object which has a few methods defined on it. Currently the wait() and link() methods are used in Nova. However the SpawnIsSynchronous fixture was returning the results of wait() directly which led to an interface mismatch. Normally utils.spawn_n returns a greenlet object which does not allow checking the return but in testing we have never blocked that capability before. This could be enhanced later to be strict for spawn_n if we choose, but it is handy to have raised exceptions pass through in testing. SpawnIsSynchronous now returns a GreenThread object lookalike which has wait() and link() methods that work as expected. This allows for the removal of the wait() method from network/model.py:NetworkInfo. A few mocks which emulated the improper behavior were also updated. Change-Id: I1ded81f93235e217822e385ddd983b24c6359a53
Diffstat (limited to 'nova/tests/unit/test_fixtures.py')
-rw-r--r--nova/tests/unit/test_fixtures.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/nova/tests/unit/test_fixtures.py b/nova/tests/unit/test_fixtures.py
index 9e9e1980af..be170d97ac 100644
--- a/nova/tests/unit/test_fixtures.py
+++ b/nova/tests/unit/test_fixtures.py
@@ -342,6 +342,46 @@ class TestSpawnIsSynchronousFixture(testtools.TestCase):
utils.spawn_n(tester.function, 'foo', bar='bar')
tester.function.assert_called_once_with('foo', bar='bar')
+ def test_spawn_return_has_wait(self):
+ self.useFixture(fixtures.SpawnIsSynchronousFixture())
+ gt = utils.spawn(lambda x: '%s' % x, 'foo')
+ foo = gt.wait()
+ self.assertEqual('foo', foo)
+
+ def test_spawn_n_return_has_wait(self):
+ self.useFixture(fixtures.SpawnIsSynchronousFixture())
+ gt = utils.spawn_n(lambda x: '%s' % x, 'foo')
+ foo = gt.wait()
+ self.assertEqual('foo', foo)
+
+ def test_spawn_has_link(self):
+ self.useFixture(fixtures.SpawnIsSynchronousFixture())
+ gt = utils.spawn(mock.MagicMock)
+ passed_arg = 'test'
+ call_count = []
+
+ def fake(thread, param):
+ self.assertEqual(gt, thread)
+ self.assertEqual(passed_arg, param)
+ call_count.append(1)
+
+ gt.link(fake, passed_arg)
+ self.assertEqual(1, len(call_count))
+
+ def test_spawn_n_has_link(self):
+ self.useFixture(fixtures.SpawnIsSynchronousFixture())
+ gt = utils.spawn_n(mock.MagicMock)
+ passed_arg = 'test'
+ call_count = []
+
+ def fake(thread, param):
+ self.assertEqual(gt, thread)
+ self.assertEqual(passed_arg, param)
+ call_count.append(1)
+
+ gt.link(fake, passed_arg)
+ self.assertEqual(1, len(call_count))
+
class TestBannedDBSchemaOperations(testtools.TestCase):
def test_column(self):