cleanups
This commit is contained in:
@@ -31,7 +31,6 @@ LOG = logging.getLogger('nova.tests.rpc')
|
|||||||
|
|
||||||
|
|
||||||
class RpcTestCase(test.TestCase):
|
class RpcTestCase(test.TestCase):
|
||||||
"""Test cases for rpc"""
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RpcTestCase, self).setUp()
|
super(RpcTestCase, self).setUp()
|
||||||
self.conn = rpc.Connection.instance(True)
|
self.conn = rpc.Connection.instance(True)
|
||||||
@@ -43,21 +42,18 @@ class RpcTestCase(test.TestCase):
|
|||||||
self.context = context.get_admin_context()
|
self.context = context.get_admin_context()
|
||||||
|
|
||||||
def test_call_succeed(self):
|
def test_call_succeed(self):
|
||||||
"""Get a value through rpc call"""
|
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.call(self.context, 'test', {"method": "echo",
|
result = rpc.call(self.context, 'test', {"method": "echo",
|
||||||
"args": {"value": value}})
|
"args": {"value": value}})
|
||||||
self.assertEqual(value, result)
|
self.assertEqual(value, result)
|
||||||
|
|
||||||
def test_call_succeed_despite_multiple_returns(self):
|
def test_call_succeed_despite_multiple_returns(self):
|
||||||
"""Get a value through rpc call"""
|
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.call(self.context, 'test', {"method": "echo_three_times",
|
result = rpc.call(self.context, 'test', {"method": "echo_three_times",
|
||||||
"args": {"value": value}})
|
"args": {"value": value}})
|
||||||
self.assertEqual(value, result)
|
self.assertEqual(value, result)
|
||||||
|
|
||||||
def test_call_succeed_despite_multiple_returns_yield(self):
|
def test_call_succeed_despite_multiple_returns_yield(self):
|
||||||
"""Get a value through rpc call"""
|
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.call(self.context, 'test',
|
result = rpc.call(self.context, 'test',
|
||||||
{"method": "echo_three_times_yield",
|
{"method": "echo_three_times_yield",
|
||||||
@@ -65,7 +61,6 @@ class RpcTestCase(test.TestCase):
|
|||||||
self.assertEqual(value, result)
|
self.assertEqual(value, result)
|
||||||
|
|
||||||
def test_multicall_succeed_once(self):
|
def test_multicall_succeed_once(self):
|
||||||
"""Get a value through rpc call"""
|
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.multicall(self.context,
|
result = rpc.multicall(self.context,
|
||||||
'test',
|
'test',
|
||||||
@@ -79,7 +74,6 @@ class RpcTestCase(test.TestCase):
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def test_multicall_succeed_three_times(self):
|
def test_multicall_succeed_three_times(self):
|
||||||
"""Get a value through rpc call"""
|
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.multicall(self.context,
|
result = rpc.multicall(self.context,
|
||||||
'test',
|
'test',
|
||||||
@@ -91,7 +85,6 @@ class RpcTestCase(test.TestCase):
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def test_multicall_succeed_three_times_yield(self):
|
def test_multicall_succeed_three_times_yield(self):
|
||||||
"""Get a value through rpc call"""
|
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.multicall(self.context,
|
result = rpc.multicall(self.context,
|
||||||
'test',
|
'test',
|
||||||
@@ -103,7 +96,7 @@ class RpcTestCase(test.TestCase):
|
|||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
def test_context_passed(self):
|
def test_context_passed(self):
|
||||||
"""Makes sure a context is passed through rpc call"""
|
"""Makes sure a context is passed through rpc call."""
|
||||||
value = 42
|
value = 42
|
||||||
result = rpc.call(self.context,
|
result = rpc.call(self.context,
|
||||||
'test', {"method": "context",
|
'test', {"method": "context",
|
||||||
@@ -111,11 +104,12 @@ class RpcTestCase(test.TestCase):
|
|||||||
self.assertEqual(self.context.to_dict(), result)
|
self.assertEqual(self.context.to_dict(), result)
|
||||||
|
|
||||||
def test_call_exception(self):
|
def test_call_exception(self):
|
||||||
"""Test that exception gets passed back properly
|
"""Test that exception gets passed back properly.
|
||||||
|
|
||||||
rpc.call returns a RemoteError object. The value of the
|
rpc.call returns a RemoteError object. The value of the
|
||||||
exception is converted to a string, so we convert it back
|
exception is converted to a string, so we convert it back
|
||||||
to an int in the test.
|
to an int in the test.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
value = 42
|
value = 42
|
||||||
self.assertRaises(rpc.RemoteError,
|
self.assertRaises(rpc.RemoteError,
|
||||||
@@ -134,7 +128,7 @@ class RpcTestCase(test.TestCase):
|
|||||||
self.assertEqual(int(exc.value), value)
|
self.assertEqual(int(exc.value), value)
|
||||||
|
|
||||||
def test_nested_calls(self):
|
def test_nested_calls(self):
|
||||||
"""Test that we can do an rpc.call inside another call"""
|
"""Test that we can do an rpc.call inside another call."""
|
||||||
class Nested(object):
|
class Nested(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def echo(context, queue, value):
|
def echo(context, queue, value):
|
||||||
@@ -162,8 +156,7 @@ class RpcTestCase(test.TestCase):
|
|||||||
self.assertEqual(value, result)
|
self.assertEqual(value, result)
|
||||||
|
|
||||||
def test_connectionpool_single(self):
|
def test_connectionpool_single(self):
|
||||||
"""Test that ConnectionPool recycles a single connection"""
|
"""Test that ConnectionPool recycles a single connection."""
|
||||||
|
|
||||||
conn1 = rpc.ConnectionPool.get()
|
conn1 = rpc.ConnectionPool.get()
|
||||||
rpc.ConnectionPool.put(conn1)
|
rpc.ConnectionPool.put(conn1)
|
||||||
conn2 = rpc.ConnectionPool.get()
|
conn2 = rpc.ConnectionPool.get()
|
||||||
@@ -171,10 +164,13 @@ class RpcTestCase(test.TestCase):
|
|||||||
self.assertEqual(conn1, conn2)
|
self.assertEqual(conn1, conn2)
|
||||||
|
|
||||||
def test_connectionpool_double(self):
|
def test_connectionpool_double(self):
|
||||||
"""Test that ConnectionPool returns 2 separate connections
|
"""Test that ConnectionPool returns and reuses separate connections.
|
||||||
when called consecutively and the pool returns connections LIFO
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
When called consecutively we should get separate connections and upon
|
||||||
|
returning them those connections should be reused for future calls
|
||||||
|
before generating a new connection.
|
||||||
|
|
||||||
|
"""
|
||||||
conn1 = rpc.ConnectionPool.get()
|
conn1 = rpc.ConnectionPool.get()
|
||||||
conn2 = rpc.ConnectionPool.get()
|
conn2 = rpc.ConnectionPool.get()
|
||||||
|
|
||||||
@@ -184,14 +180,11 @@ class RpcTestCase(test.TestCase):
|
|||||||
|
|
||||||
conn3 = rpc.ConnectionPool.get()
|
conn3 = rpc.ConnectionPool.get()
|
||||||
conn4 = rpc.ConnectionPool.get()
|
conn4 = rpc.ConnectionPool.get()
|
||||||
self.assertEqual(conn2, conn3)
|
self.assertEqual(conn1, conn3)
|
||||||
self.assertEqual(conn1, conn4)
|
self.assertEqual(conn2, conn4)
|
||||||
|
|
||||||
def test_connectionpool_limit(self):
|
def test_connectionpool_limit(self):
|
||||||
"""Test connection pool limit and verify all connections
|
"""Test connection pool limit and connection uniqueness."""
|
||||||
are unique
|
|
||||||
"""
|
|
||||||
|
|
||||||
max_size = FLAGS.rpc_conn_pool_size
|
max_size = FLAGS.rpc_conn_pool_size
|
||||||
conns = []
|
conns = []
|
||||||
|
|
||||||
@@ -205,19 +198,21 @@ class RpcTestCase(test.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestReceiver(object):
|
class TestReceiver(object):
|
||||||
"""Simple Proxy class so the consumer has methods to call
|
"""Simple Proxy class so the consumer has methods to call.
|
||||||
|
|
||||||
Uses static methods because we aren't actually storing any state"""
|
Uses static methods because we aren't actually storing any state.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def echo(context, value):
|
def echo(context, value):
|
||||||
"""Simply returns whatever value is sent in"""
|
"""Simply returns whatever value is sent in."""
|
||||||
LOG.debug(_("Received %s"), value)
|
LOG.debug(_("Received %s"), value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def context(context, value):
|
def context(context, value):
|
||||||
"""Returns dictionary version of context"""
|
"""Returns dictionary version of context."""
|
||||||
LOG.debug(_("Received %s"), context)
|
LOG.debug(_("Received %s"), context)
|
||||||
return context.to_dict()
|
return context.to_dict()
|
||||||
|
|
||||||
@@ -235,5 +230,5 @@ class TestReceiver(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fail(context, value):
|
def fail(context, value):
|
||||||
"""Raises an exception with the value sent in"""
|
"""Raises an exception with the value sent in."""
|
||||||
raise Exception(value)
|
raise Exception(value)
|
||||||
|
|||||||
Reference in New Issue
Block a user