This commit is contained in:
termie
2011-05-25 15:43:04 -07:00
parent e9f4f8b45c
commit fdb0c5a874

View File

@@ -31,7 +31,6 @@ LOG = logging.getLogger('nova.tests.rpc')
class RpcTestCase(test.TestCase):
"""Test cases for rpc"""
def setUp(self):
super(RpcTestCase, self).setUp()
self.conn = rpc.Connection.instance(True)
@@ -43,21 +42,18 @@ class RpcTestCase(test.TestCase):
self.context = context.get_admin_context()
def test_call_succeed(self):
"""Get a value through rpc call"""
value = 42
result = rpc.call(self.context, 'test', {"method": "echo",
"args": {"value": value}})
self.assertEqual(value, result)
def test_call_succeed_despite_multiple_returns(self):
"""Get a value through rpc call"""
value = 42
result = rpc.call(self.context, 'test', {"method": "echo_three_times",
"args": {"value": value}})
self.assertEqual(value, result)
def test_call_succeed_despite_multiple_returns_yield(self):
"""Get a value through rpc call"""
value = 42
result = rpc.call(self.context, 'test',
{"method": "echo_three_times_yield",
@@ -65,7 +61,6 @@ class RpcTestCase(test.TestCase):
self.assertEqual(value, result)
def test_multicall_succeed_once(self):
"""Get a value through rpc call"""
value = 42
result = rpc.multicall(self.context,
'test',
@@ -79,7 +74,6 @@ class RpcTestCase(test.TestCase):
i += 1
def test_multicall_succeed_three_times(self):
"""Get a value through rpc call"""
value = 42
result = rpc.multicall(self.context,
'test',
@@ -91,7 +85,6 @@ class RpcTestCase(test.TestCase):
i += 1
def test_multicall_succeed_three_times_yield(self):
"""Get a value through rpc call"""
value = 42
result = rpc.multicall(self.context,
'test',
@@ -103,7 +96,7 @@ class RpcTestCase(test.TestCase):
i += 1
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
result = rpc.call(self.context,
'test', {"method": "context",
@@ -111,11 +104,12 @@ class RpcTestCase(test.TestCase):
self.assertEqual(self.context.to_dict(), result)
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
exception is converted to a string, so we convert it back
to an int in the test.
"""
value = 42
self.assertRaises(rpc.RemoteError,
@@ -134,7 +128,7 @@ class RpcTestCase(test.TestCase):
self.assertEqual(int(exc.value), value)
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):
@staticmethod
def echo(context, queue, value):
@@ -162,8 +156,7 @@ class RpcTestCase(test.TestCase):
self.assertEqual(value, result)
def test_connectionpool_single(self):
"""Test that ConnectionPool recycles a single connection"""
"""Test that ConnectionPool recycles a single connection."""
conn1 = rpc.ConnectionPool.get()
rpc.ConnectionPool.put(conn1)
conn2 = rpc.ConnectionPool.get()
@@ -171,10 +164,13 @@ class RpcTestCase(test.TestCase):
self.assertEqual(conn1, conn2)
def test_connectionpool_double(self):
"""Test that ConnectionPool returns 2 separate connections
when called consecutively and the pool returns connections LIFO
"""
"""Test that ConnectionPool returns and reuses separate connections.
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()
conn2 = rpc.ConnectionPool.get()
@@ -184,14 +180,11 @@ class RpcTestCase(test.TestCase):
conn3 = rpc.ConnectionPool.get()
conn4 = rpc.ConnectionPool.get()
self.assertEqual(conn2, conn3)
self.assertEqual(conn1, conn4)
self.assertEqual(conn1, conn3)
self.assertEqual(conn2, conn4)
def test_connectionpool_limit(self):
"""Test connection pool limit and verify all connections
are unique
"""
"""Test connection pool limit and connection uniqueness."""
max_size = FLAGS.rpc_conn_pool_size
conns = []
@@ -205,19 +198,21 @@ class RpcTestCase(test.TestCase):
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
def echo(context, value):
"""Simply returns whatever value is sent in"""
"""Simply returns whatever value is sent in."""
LOG.debug(_("Received %s"), value)
return value
@staticmethod
def context(context, value):
"""Returns dictionary version of context"""
"""Returns dictionary version of context."""
LOG.debug(_("Received %s"), context)
return context.to_dict()
@@ -235,5 +230,5 @@ class TestReceiver(object):
@staticmethod
def fail(context, value):
"""Raises an exception with the value sent in"""
"""Raises an exception with the value sent in."""
raise Exception(value)