Ejemplo n.º 1
0
    def test_old_tasks(frozen_time, _):  # pylint: disable=no-self-argument
        tk = TaskHeaderKeeper(environments_manager=EnvironmentsManager(),
                              node=p2p.Node(),
                              min_price=10)
        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)
        task_header = get_task_header()
        task_header.fixed_header.deadline = timeout_to_deadline(10)
        assert tk.add_task_header(task_header)

        task_id = task_header.task_id
        task_header2 = get_task_header("abc")
        task_header2.fixed_header.deadline = timeout_to_deadline(1)
        task_id2 = task_header2.task_id
        assert tk.add_task_header(task_header2)
        assert tk.task_headers.get(task_id2) is not None
        assert tk.task_headers.get(task_id) is not None
        assert tk.removed_tasks.get(task_id2) is None
        assert tk.removed_tasks.get(task_id) is None
        assert len(tk.supported_tasks) == 2

        frozen_time.tick(timedelta(seconds=1.1))  # pylint: disable=no-member
        tk.remove_old_tasks()
        assert tk.task_headers.get(task_id2) is None
        assert tk.task_headers.get(task_id) is not None
        assert tk.removed_tasks.get(task_id2) is not None
        assert tk.removed_tasks.get(task_id) is None
        assert len(tk.supported_tasks) == 1
        assert tk.supported_tasks[0] == task_id
Ejemplo n.º 2
0
    def test_task_limit(frozen_time, self):  # pylint: disable=no-self-argument
        tk = TaskHeaderKeeper(environments_manager=EnvironmentsManager(),
                              node=p2p.Node(),
                              min_price=10)
        limit = tk.max_tasks_per_requestor

        thd = get_task_header("ta")
        thd.fixed_header.deadline = timeout_to_deadline(0.1)
        tk.add_task_header(thd)

        ids = [thd.task_id]
        for i in range(1, limit):
            thd = get_task_header("ta")
            ids.append(thd.task_id)
            tk.add_task_header(thd)
        last_add_time = time.time()

        for id_ in ids:
            self.assertIn(id_, tk.task_headers)

        thd = get_task_header("tb0")
        tb_id = thd.task_id
        tk.add_task_header(thd)

        for id_ in ids:
            self.assertIn(id_, tk.task_headers)

        self.assertIn(tb_id, tk.task_headers)

        while time.time() == last_add_time:
            frozen_time.tick(  # pylint: disable=no-member
                delta=timedelta(milliseconds=100))

        thd = get_task_header("ta")
        new_task_id = thd.task_id
        tk.add_task_header(thd)
        self.assertNotIn(new_task_id, tk.task_headers)

        for id_ in ids:
            self.assertIn(id_, tk.task_headers)
        self.assertIn(tb_id, tk.task_headers)

        frozen_time.tick(  # pylint: disable=no-member
            delta=timedelta(milliseconds=100))
        tk.remove_old_tasks()

        thd = get_task_header("ta")
        new_task_id = thd.task_id
        tk.add_task_header(thd)
        self.assertIn(new_task_id, tk.task_headers)

        self.assertNotIn(ids[0], tk.task_headers)
        for i in range(1, limit):
            self.assertIn(ids[i], tk.task_headers)
        self.assertIn(tb_id, tk.task_headers)
Ejemplo n.º 3
0
 def test_old_tasks(self):
     tk = TaskHeaderKeeper(EnvironmentsManager(), 10)
     e = Environment()
     e.accept_tasks = True
     tk.environments_manager.add_environment(e)
     task_header = get_dict_task_header()
     task_header["deadline"] = timeout_to_deadline(10)
     assert tk.add_task_header(task_header)
     task_header["deadline"] = timeout_to_deadline(1)
     task_header["task_id"] = "abc"
     assert tk.add_task_header(task_header)
     assert tk.task_headers.get("abc") is not None
     assert tk.task_headers.get("xyz") is not None
     assert tk.removed_tasks.get("abc") is None
     assert tk.removed_tasks.get("xyz") is None
     assert len(tk.supported_tasks) == 2
     time.sleep(1.1)
     tk.remove_old_tasks()
     assert tk.task_headers.get("abc") is None
     assert tk.task_headers.get("xyz") is not None
     assert tk.removed_tasks.get("abc") is not None
     assert tk.removed_tasks.get("xyz") is None
     assert len(tk.supported_tasks) == 1
     assert tk.supported_tasks[0] == "xyz"