Fix handling of None, etc. replies
A rather embarassing and obvious bug - we're currently not allowing endpoint methods to send replies of None, '', False, [], {}, etc. Change-Id: Ifc5ff8f308f526197559a4df7bed244cff6ed3c1
This commit is contained in:
parent
f95c5bb6ed
commit
747e1a4099
@ -32,9 +32,7 @@ class ExecutorBase(object):
|
|||||||
|
|
||||||
def _dispatch(self, incoming):
|
def _dispatch(self, incoming):
|
||||||
try:
|
try:
|
||||||
reply = self.callback(incoming.ctxt, incoming.message)
|
incoming.reply(self.callback(incoming.ctxt, incoming.message))
|
||||||
if reply:
|
|
||||||
incoming.reply(reply)
|
|
||||||
except messaging.ExpectedException as e:
|
except messaging.ExpectedException as e:
|
||||||
_LOG.debug('Expected exception during message handling (%s)' %
|
_LOG.debug('Expected exception during message handling (%s)' %
|
||||||
e.exc_info[1])
|
e.exc_info[1])
|
||||||
|
@ -46,10 +46,10 @@ class ServerSetupMixin(object):
|
|||||||
class TestSerializer(object):
|
class TestSerializer(object):
|
||||||
|
|
||||||
def serialize_entity(self, ctxt, entity):
|
def serialize_entity(self, ctxt, entity):
|
||||||
return 's' + (entity or '')
|
return ('s' + entity) if entity else entity
|
||||||
|
|
||||||
def deserialize_entity(self, ctxt, entity):
|
def deserialize_entity(self, ctxt, entity):
|
||||||
return 'd' + (entity or '')
|
return ('d' + entity) if entity else entity
|
||||||
|
|
||||||
def serialize_context(self, ctxt):
|
def serialize_context(self, ctxt):
|
||||||
return dict([(k, 's' + v) for k, v in ctxt.items()])
|
return dict([(k, 's' + v) for k, v in ctxt.items()])
|
||||||
@ -228,6 +228,11 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
|
|||||||
server_thread = self._setup_server(transport, TestEndpoint())
|
server_thread = self._setup_server(transport, TestEndpoint())
|
||||||
client = self._setup_client(transport)
|
client = self._setup_client(transport)
|
||||||
|
|
||||||
|
self.assertIsNone(client.call({}, 'ping', arg=None))
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg=0), 0)
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg=False), False)
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg=[]), [])
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg={}), {})
|
||||||
self.assertEqual(client.call({}, 'ping', arg='foo'), 'dsdsfoo')
|
self.assertEqual(client.call({}, 'ping', arg='foo'), 'dsdsfoo')
|
||||||
|
|
||||||
self._stop_server(client, server_thread)
|
self._stop_server(client, server_thread)
|
||||||
@ -243,6 +248,11 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
|
|||||||
client = self._setup_client(transport)
|
client = self._setup_client(transport)
|
||||||
|
|
||||||
direct = client.prepare(server='testserver')
|
direct = client.prepare(server='testserver')
|
||||||
|
self.assertIsNone(direct.call({}, 'ping', arg=None))
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg=0), 0)
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg=False), False)
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg=[]), [])
|
||||||
|
self.assertEqual(client.call({}, 'ping', arg={}), {})
|
||||||
self.assertEqual(direct.call({}, 'ping', arg='foo'), 'dsdsfoo')
|
self.assertEqual(direct.call({}, 'ping', arg='foo'), 'dsdsfoo')
|
||||||
|
|
||||||
self._stop_server(client, server_thread)
|
self._stop_server(client, server_thread)
|
||||||
|
Loading…
Reference in New Issue
Block a user