tests: 'fix' responder test.

Needs a complete rewrite, but this will do for now.
This commit is contained in:
David Wilson 2018-04-16 16:58:44 +01:00
parent f9eb66e76e
commit ce6fb05d87
3 changed files with 29 additions and 21 deletions

View File

@ -646,7 +646,7 @@ class ModuleResponder(object):
except Exception:
LOG.debug('While importing %r', fullname, exc_info=True)
msg.reply((fullname, None, None, None, []),
msg.reply((fullname, None, None, None, ()),
handle=mitogen.core.LOAD_MODULE)

View File

@ -2,17 +2,14 @@
I am a self-contained program!
"""
import mitogen.master
import mitogen
def repr_stuff():
return repr([__name__, 50])
@mitogen.main()
def main(router):
context = router.local()
print context.call(repr_stuff)
if __name__ == '__main__' and mitogen.is_master:
import mitogen.utils
mitogen.utils.run_with_router(main)

View File

@ -39,20 +39,26 @@ class BrokenModulesTest(unittest2.TestCase):
# Ensure we don't crash in the case of a module legitimately being
# unavailable. Should never happen in the real world.
stream = mock.Mock()
stream.sent_modules = set()
router = mock.Mock()
responder = mitogen.master.ModuleResponder(router)
responder._on_get_module(
mitogen.core.Message(
data='non_existent_module',
reply_to=50,
)
router.stream_by_id = lambda n: stream
msg = mitogen.core.Message(
data='non_existent_module',
reply_to=50,
)
msg.router = router
responder = mitogen.master.ModuleResponder(router)
responder._on_get_module(msg)
self.assertEquals(1, len(router.route.mock_calls))
call = router.route.mock_calls[0]
msg, = call[1]
self.assertEquals(50, msg.handle)
self.assertIsNone(msg.unpickle())
self.assertEquals(mitogen.core.LOAD_MODULE, msg.handle)
self.assertEquals(('non_existent_module', None, None, None, ()),
msg.unpickle())
def test_ansible_six_messed_up_path(self):
# The copy of six.py shipped with Ansible appears in a package whose
@ -62,19 +68,24 @@ class BrokenModulesTest(unittest2.TestCase):
# cause an attempt to request ansible.compat.six._six from the master.
import six_brokenpkg
stream = mock.Mock()
stream.sent_modules = set()
router = mock.Mock()
responder = mitogen.master.ModuleResponder(router)
responder._on_get_module(
mitogen.core.Message(
data='six_brokenpkg._six',
reply_to=50,
)
router.stream_by_id = lambda n: stream
msg = mitogen.core.Message(
data='six_brokenpkg._six',
reply_to=50,
)
msg.router = router
responder = mitogen.master.ModuleResponder(router)
responder._on_get_module(msg)
self.assertEquals(1, len(router.route.mock_calls))
call = router.route.mock_calls[0]
msg, = call[1]
self.assertEquals(50, msg.handle)
self.assertEquals(mitogen.core.LOAD_MODULE, msg.handle)
self.assertIsInstance(msg.unpickle(), tuple)