diff --git a/mitogen/core.py b/mitogen/core.py index 66842852..70c2f588 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -864,7 +864,7 @@ class Stream(BasicStream): self._router = router self.remote_id = remote_id self.name = 'default' - self.sent_modules = set() + self.sent_modules = set(['mitogen', 'mitogen.core']) self.construct(**kwargs) self._input_buf = collections.deque() self._output_buf = collections.deque() diff --git a/mitogen/master.py b/mitogen/master.py index cce9a292..8c06ef8f 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -593,6 +593,7 @@ class ModuleResponder(object): mitogen.core.Message( data='%s\x00%s' % (context.context_id, fullname), handle=mitogen.core.FORWARD_MODULE, + dst_id=stream.remote_id, ) ) diff --git a/mitogen/parent.py b/mitogen/parent.py index bec03f85..1d645f23 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -1231,7 +1231,7 @@ class ModuleForwarder(object): if msg.is_dead: return - context_id_s, fullname = msg.data.partition('\x00') + context_id_s, _, fullname = msg.data.partition('\x00') context_id = int(context_id_s) stream = self.router.stream_by_id(context_id) if stream.remote_id == mitogen.parent_id: @@ -1239,15 +1239,18 @@ class ModuleForwarder(object): self, context_id, fullname) return + if fullname in stream.sent_modules: + return + LOG.debug('%r._on_forward_module() sending %r to %r via %r', self, fullname, context_id, stream.remote_id) self._send_module_and_related(stream, fullname) if stream.remote_id != context_id: stream._send( mitogen.core.Message( - dst_id=stream.remote_id, - handle=mitogen.core.FORWARD_MODULE, data=msg.data, + handle=mitogen.core.FORWARD_MODULE, + dst_id=stream.remote_id, ) ) diff --git a/tests/minimize_source_test.py b/tests/minimize_source_test.py index 857fc339..b98cdebd 100644 --- a/tests/minimize_source_test.py +++ b/tests/minimize_source_test.py @@ -1,7 +1,6 @@ import unittest2 -from mitogen.parent import minimize_source - +import mitogen.minify import testlib @@ -14,40 +13,42 @@ def read_sample(fname): class MinimizeSource(unittest2.TestCase): + func = staticmethod(mitogen.minify.minimize_source) + def test_class(self): original = read_sample('class.py') expected = read_sample('class_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) def test_comment(self): original = read_sample('comment.py') expected = read_sample('comment_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) def test_def(self): original = read_sample('def.py') expected = read_sample('def_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) def test_hashbang(self): original = read_sample('hashbang.py') expected = read_sample('hashbang_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) def test_mod(self): original = read_sample('mod.py') expected = read_sample('mod_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) def test_pass(self): original = read_sample('pass.py') expected = read_sample('pass_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) def test_obstacle_course(self): original = read_sample('obstacle_course.py') expected = read_sample('obstacle_course_min.py') - self.assertEqual(expected, minimize_source(original)) + self.assertEqual(expected, self.func(original)) if __name__ == '__main__': diff --git a/tests/module_finder_test.py b/tests/module_finder_test.py index c4b65e11..1c77bdee 100644 --- a/tests/module_finder_test.py +++ b/tests/module_finder_test.py @@ -200,6 +200,7 @@ class FindRelatedTest(testlib.TestCase): 'mitogen.compat.functools', 'mitogen.core', 'mitogen.master', + 'mitogen.minify', 'mitogen.parent', ]) diff --git a/tests/responder_test.py b/tests/responder_test.py index 837beb3e..3f6f66a9 100644 --- a/tests/responder_test.py +++ b/tests/responder_test.py @@ -52,9 +52,9 @@ class BrokenModulesTest(unittest2.TestCase): responder = mitogen.master.ModuleResponder(router) responder._on_get_module(msg) - self.assertEquals(1, len(router.route.mock_calls)) + self.assertEquals(1, len(router._async_route.mock_calls)) - call = router.route.mock_calls[0] + call = router._async_route.mock_calls[0] msg, = call[1] self.assertEquals(mitogen.core.LOAD_MODULE, msg.handle) self.assertEquals(('non_existent_module', None, None, None, ()), @@ -81,9 +81,9 @@ class BrokenModulesTest(unittest2.TestCase): responder = mitogen.master.ModuleResponder(router) responder._on_get_module(msg) - self.assertEquals(1, len(router.route.mock_calls)) + self.assertEquals(1, len(router._async_route.mock_calls)) - call = router.route.mock_calls[0] + call = router._async_route.mock_calls[0] msg, = call[1] self.assertEquals(mitogen.core.LOAD_MODULE, msg.handle) self.assertIsInstance(msg.unpickle(), tuple)