Exemplo n.º 1
0
 def run_assertions(reactor: ReactorInterface):
     cb1 = ReactorCommand.create_callback(callback=ROUTE_CALLBACK,
                                          envelope=env1)
     cb2 = ReactorCommand.create_callback(callback=ROUTE_CALLBACK,
                                          envelope=env2)
     reactor._run_callback.assert_has_calls(
         [call(cb1), call(cb2)], any_order=False)
Exemplo n.º 2
0
    async def _lookup_ip(self, cmd, url, vk, *args, **kwargs):
        ip, node = None, None
        try:
            node = await self.dht.network.lookup_ip(vk)
        except Exception as e:
            delim_line = '!' * 64
            err_msg = '\n\n' + delim_line + '\n' + delim_line
            err_msg += '\n ERROR CAUGHT IN LOOKUP FUNCTION {}\ncalled \w args={}\nand kwargs={}\n'\
                        .format(args, kwargs)
            err_msg += '\nError Message: '
            err_msg += '\n\n{}'.format(traceback.format_exc())
            err_msg += '\n' + delim_line + '\n' + delim_line
            self.log.error(err_msg)

        if node is None:

            kwargs = cmd.kwargs
            callback = ReactorCommand.create_callback(
                callback=StateInput.LOOKUP_FAILED, **kwargs)
            self.log.debug(
                "Sending callback failure to mainthread {}".format(callback))
            self.socket.send(callback.serialize())
            # TODO -- send callback to SM saying hey i couldnt lookup this vk

            return

        # Send interpolated command back through pipeline
        ip = node.ip if type(node) == Node else node
        new_url = IPUtils.interpolate_url(url, ip)
        kwargs = cmd.kwargs
        kwargs['url'] = new_url
        new_cmd = ReactorCommand.create_cmd(envelope=cmd.envelope, **kwargs)

        self._execute_cmd(new_cmd)
Exemplo n.º 3
0
    def call_on_mp(self, callback: str, header: str=None, envelope_binary: bytes=None, **kwargs):
        if header:
            kwargs['header'] = header

        cmd = ReactorCommand.create_callback(callback=callback, envelope_binary=envelope_binary, **kwargs)

        # self.log.critical("\ncalling callback cmd to reactor interface: {}".format(cmd))  # DEBUG line remove this

        self.inproc_socket.send(cmd.serialize())
Exemplo n.º 4
0
    def test_create_callback(self):
        """
        Tests create_callback
        """
        callback = 'route'
        kwargs = {'cats': '18', 'dogs': 'over 9000'}

        cmd = ReactorCommand.create_callback(callback, **kwargs)

        self.assertEqual(cmd.callback, callback)
        for k in kwargs:
            self.assertEqual(cmd.kwargs[k], kwargs[k])
Exemplo n.º 5
0
 def run_assertions(reactor: ReactorInterface):
     callback = ReactorCommand.create_callback(callback=ROUTE_CALLBACK,
                                               envelope=env)
     reactor._run_callback.assert_called_once_with(callback)
Exemplo n.º 6
0
 def run_assertions(reactor: ReactorInterface):
     cb = ReactorCommand.create_callback(callback=ROUTE_REQ_CALLBACK,
                                         envelope=env,
                                         header=DEALER_ID)
     reactor._run_callback.assert_called_once_with(cb)
Exemplo n.º 7
0
 def assert_dealer(reactor: ReactorInterface):
     cb = ReactorCommand.create_callback(callback=ROUTE_CALLBACK,
                                         envelope=rep_env)
     reactor._run_callback.assert_called_once_with(cb)