Beispiel #1
0
def run_requesting_node(datadir, num_subtasks=3):
    client = None

    def shutdown():
        client and client.quit()
        reactor.running and reactor.callFromThread(reactor.stop)
        logging.shutdown()
        if os.path.exists(datadir):
            _print_golem_log(datadir)
            shutil.rmtree(datadir)

    atexit.register(shutdown)

    global node_kind
    node_kind = "REQUESTOR"

    start_time = time.time()
    report("Starting in {}".format(datadir))
    from golem.core.common import config_logging
    config_logging(datadir=datadir, loglevel="DEBUG")

    client = create_client(datadir)
    client.are_terms_accepted = lambda: True
    client.start()
    report("Started in {:.1f} s".format(time.time() - start_time))

    dummy_env = DummyEnvironment()
    client.environments_manager.add_environment(dummy_env)

    params = DummyTaskParameters(1024, 2048, 256, 0x0001ffff)
    task = DummyTask(client.get_node_name(), params, num_subtasks,
                     client.keys_auth.public_key)
    task.initialize(DirManager(datadir))
    task_rpc.enqueue_new_task(client, task)

    port = client.p2pservice.cur_port
    requestor_addr = "{}:{}".format(client.node.prv_addr, port)
    report("Listening on {}".format(requestor_addr))

    def report_status():
        while True:
            time.sleep(1)
            if not task.finished_computation():
                continue
            if task.verify_task():
                report("Task finished")
            else:
                report("Task failed")
            shutdown()
            return

    reactor.callInThread(report_status)
    reactor.run()
    return client  # Used in tests, with mocked reactor
Beispiel #2
0
 def test_general_exception(self, start_mock, log_mock, *_):
     start_mock.side_effect = RuntimeError("TEST ERROR")
     task = self.client.task_manager.create_task(self.t_dict)
     deferred = rpc.enqueue_new_task(self.client, task)
     with self.assertRaises(RuntimeError):
         golem_deferred.sync_wait(deferred)
     log_mock.assert_called_once()
Beispiel #3
0
 def test_ethereum_error(self, deposit_mock, log_mock, *_):
     from golem.ethereum import exceptions as eth_exceptions
     deposit_mock.side_effect = eth_exceptions.EthereumError('TEST ERROR')
     task = self.client.task_manager.create_task(self.t_dict)
     deferred = rpc.enqueue_new_task(self.client, task)
     with self.assertRaises(eth_exceptions.EthereumError):
         golem_deferred.sync_wait(deferred)
     log_mock.assert_called_once()
Beispiel #4
0
 def test_ensure_task_deposit(self, *_):
     force = fake.pybool()
     self.client.concent_service = mock.Mock()
     self.client.concent_service.enabled = True
     self.t_dict['concent_enabled'] = True
     task = self.client.task_manager.create_task(self.t_dict)
     deferred = rpc.enqueue_new_task(self.client, task, force=force)
     golem_deferred.sync_wait(deferred)
     self.client.transaction_system.concent_deposit.assert_called_once_with(
         required=mock.ANY,
         expected=mock.ANY,
         force=force,
     )
Beispiel #5
0
    def test_enqueue_new_task(self, *_):
        c = self.client
        c.task_server.task_manager.key_id = 'deadbeef'
        c.p2pservice.get_estimated_network_size.return_value = 0

        task = self.client.task_manager.create_task(self.t_dict)
        deferred = rpc.enqueue_new_task(self.client, task)
        task = golem_deferred.sync_wait(deferred)
        task_id = task.header.task_id
        assert isinstance(task, taskbase.Task)
        assert task.header.task_id
        assert c.resource_server.add_task.called

        c.task_server.task_manager.tasks[task_id] = task
        c.task_server.task_manager.tasks_states[task_id] = taskstate.TaskState(
        )
        frames = c.task_server.task_manager.get_output_states(task_id)
        assert frames is not None
Beispiel #6
0
 def setUp(self):
     super().setUp()
     self.task = self.client.task_manager.create_task(self.t_dict)
     with mock.patch('os.path.getsize'):
         golem_deferred.sync_wait(
             rpc.enqueue_new_task(self.client, self.task), )
Beispiel #7
0
    def test_restart_task(self, connect_to_network, *_):
        self.client.apps_manager.load_all_apps()

        deferred = defer.Deferred()
        connect_to_network.side_effect = lambda *_: deferred.callback(True)
        self.client.are_terms_accepted = lambda: True
        self.client.start()
        golem_deferred.sync_wait(deferred)

        def create_resource_package(*_args):
            result = 'package_path', 'package_sha1'
            return test_client.done_deferred(result)

        def add_task(*_args, **_kwargs):
            resource_manager_result = 'res_hash', ['res_file_1']
            result = resource_manager_result, 'res_file_1', 'package_hash', 0
            return test_client.done_deferred(result)

        self.client.resource_server = mock.Mock(
            create_resource_package=mock.Mock(
                side_effect=create_resource_package, ),
            add_task=mock.Mock(side_effect=add_task))

        task_manager = self.client.task_server.task_manager

        task_manager.dump_task = mock.Mock()

        some_file_path = self.new_path / "foo"
        # pylint thinks it's PurePath, but it's a concrete path
        some_file_path.touch()  # pylint: disable=no-member

        task_dict = {
            'bid': 5.0,
            'compute_on': 'cpu',
            'name': 'test task',
            'options': {
                'difficulty': 1337,
                'output_path': '',
            },
            'resources': [str(some_file_path)],
            'subtask_timeout': common.timeout_to_string(3),
            'subtasks_count': 1,
            'timeout': common.timeout_to_string(3),
            'type': 'Dummy',
        }

        task = self.client.task_manager.create_task(task_dict)
        golem_deferred.sync_wait(rpc.enqueue_new_task(self.client, task))
        with mock.patch('golem.task.rpc.enqueue_new_task') as enq_mock:
            new_task_id, error = self.provider.restart_task(
                task.header.task_id)
            enq_mock.assert_called_once()
        assert new_task_id
        assert not error

        assert task.header.task_id != new_task_id
        assert task_manager.tasks_states[
            task.header.task_id].status == taskstate.TaskStatus.restarted
        old_subtask_states = task_manager.tasks_states[task.header.task_id] \
            .subtask_states.values()
        assert all(ss.subtask_status == taskstate.SubtaskStatus.restarted
                   for ss in old_subtask_states)