Exemplo n.º 1
0
    def test_task_header_update(self):
        e = Environment()
        e.accept_tasks = True

        tk = TaskHeaderKeeper(EnvironmentsManager(), 10)
        tk.environments_manager.add_environment(e)

        assert not tk.add_task_header(dict())

        task_header = get_dict_task_header()
        task_id = task_header["task_id"]

        task_header["deadline"] = timeout_to_deadline(10)
        assert tk.add_task_header(task_header)
        assert task_id in tk.supported_tasks
        assert tk.add_task_header(task_header)
        assert task_id in tk.supported_tasks

        task_header["max_price"] = 1
        assert tk.add_task_header(task_header)
        assert task_id not in tk.supported_tasks

        tk.task_headers = {}
        tk.supported_tasks = []

        task_header["max_price"] = 1
        assert tk.add_task_header(task_header)
        assert task_id not in tk.supported_tasks

        task_header['task_id'] = "newtaskID"
        task_header['deadline'] = "WRONG DEADLINE"
        assert not tk.add_task_header(task_header)
Exemplo n.º 2
0
    def test_task_header_update(self):
        e = Environment()
        e.accept_tasks = True

        tk = TaskHeaderKeeper(environments_manager=EnvironmentsManager(),
                              node=p2p.Node(),
                              min_price=10)
        tk.environments_manager.add_environment(e)

        task_header = get_task_header()
        task_id = task_header.task_id

        task_header.fixed_header.deadline = timeout_to_deadline(10)
        task_header.fixed_header.update_checksum()
        assert tk.add_task_header(task_header)
        assert task_id in tk.supported_tasks
        assert tk.add_task_header(task_header)
        assert task_id in tk.supported_tasks

        task_header = copy.deepcopy(task_header)
        task_header.fixed_header.max_price = 1
        task_header.fixed_header.update_checksum()
        # An attempt to update fixed header should *not* succeed
        assert not tk.add_task_header(task_header)
        assert task_id in tk.supported_tasks

        tk.task_headers = {}
        tk.supported_tasks = []

        assert tk.add_task_header(task_header)
        assert task_id not in tk.supported_tasks