Exemplo n.º 1
0
 def test_is_supported(self):
     tk = TaskHeaderKeeper(EnvironmentsManager(), 10.0)
     self.assertFalse(tk.is_supported({}))
     task = {"environment": Environment.get_id(), 'max_price': 0}
     self.assertFalse(tk.is_supported(task))
     e = Environment()
     e.accept_tasks = True
     tk.environments_manager.add_environment(e)
     self.assertFalse(tk.is_supported(task))
     task["max_price"] = 10.0
     self.assertFalse(tk.is_supported(task))
     task["min_version"] = APP_VERSION
     self.assertTrue(tk.is_supported(task))
     task["max_price"] = 10.5
     self.assertTrue(tk.is_supported(task))
     config_desc = Mock()
     config_desc.min_price = 13.0
     tk.change_config(config_desc)
     self.assertFalse(tk.is_supported(task))
     config_desc.min_price = 10.0
     tk.change_config(config_desc)
     self.assertTrue(tk.is_supported(task))
     task["min_version"] = "120"
     self.assertFalse(tk.is_supported(task))
     task["min_version"] = tk.app_version
     self.assertTrue(tk.is_supported(task))
     task["min_version"] = "abc"
     with self.assertLogs(logger=logger, level=1):
         self.assertFalse(tk.is_supported(task))
Exemplo n.º 2
0
    def test_is_supported(self):
        em = EnvironmentsManager()
        em.environments = {}
        em.support_statuses = {}

        tk = TaskHeaderKeeper(environments_manager=EnvironmentsManager(),
                              node=p2p.Node(),
                              min_price=10.0)

        header = get_task_header()
        header.fixed_header.environment = None
        header.fixed_header.max_price = None
        header.fixed_header.min_version = None
        self.assertFalse(tk.check_support(header))

        header.fixed_header.environment = Environment.get_id()
        header.fixed_header.max_price = 0
        supported = tk.check_support(header)
        self.assertFalse(supported)
        self.assertIn(UnsupportReason.ENVIRONMENT_MISSING, supported.desc)

        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)
        supported = tk.check_support(header)
        self.assertFalse(supported)
        self.assertIn(UnsupportReason.MAX_PRICE, supported.desc)

        header.fixed_header.max_price = 10.0
        supported = tk.check_support(header)
        self.assertFalse(supported)
        self.assertIn(UnsupportReason.APP_VERSION, supported.desc)

        header.fixed_header.min_version = golem.__version__
        self.assertTrue(tk.check_support(header))

        header.fixed_header.max_price = 10.0
        self.assertTrue(tk.check_support(header))

        config_desc = mock.Mock()
        config_desc.min_price = 13.0
        tk.change_config(config_desc)
        self.assertFalse(tk.check_support(header))

        config_desc.min_price = 10.0
        tk.change_config(config_desc)
        self.assertTrue(tk.check_support(header))

        header.fixed_header.min_version = "120"
        self.assertFalse(tk.check_support(header))

        header.fixed_header.min_version = tk.app_version
        self.assertTrue(tk.check_support(header))

        header.fixed_header.min_version = "abc"
        with self.assertLogs(logger=logger, level='WARNING'):
            self.assertFalse(tk.check_support(header))
Exemplo n.º 3
0
 def test_change_config(self):
     tk = TaskHeaderKeeper(EnvironmentsManager(), 10.0)
     e = Environment()
     e.accept_tasks = True
     tk.environments_manager.add_environment(e)
     task_header = get_dict_task_header()
     task_header["max_price"] = 9.0
     tk.add_task_header(task_header)
     self.assertNotIn("xyz", tk.supported_tasks)
     self.assertIsNotNone(tk.task_headers["xyz"])
     task_header["task_id"] = "abc"
     task_header["max_price"] = 10.0
     tk.add_task_header(task_header)
     self.assertIn("abc", tk.supported_tasks)
     self.assertIsNotNone(tk.task_headers["abc"])
     config_desc = Mock()
     config_desc.min_price = 10.0
     tk.change_config(config_desc)
     self.assertNotIn("xyz", tk.supported_tasks)
     self.assertIn("abc", tk.supported_tasks)
     config_desc.min_price = 8.0
     tk.change_config(config_desc)
     self.assertIn("xyz", tk.supported_tasks)
     self.assertIn("abc", tk.supported_tasks)
     config_desc.min_price = 11.0
     tk.change_config(config_desc)
     self.assertNotIn("xyz", tk.supported_tasks)
     self.assertNotIn("abc", tk.supported_tasks)
Exemplo n.º 4
0
    def test_change_config(self, tar):
        tk = TaskHeaderKeeper(environments_manager=EnvironmentsManager(),
                              node=p2p.Node(),
                              min_price=10.0,
                              task_archiver=tar)
        e = Environment()
        e.accept_tasks = True
        tk.environments_manager.add_environment(e)

        task_header = get_task_header()
        task_id = task_header.task_id
        task_header.fixed_header.max_price = 9.0
        tk.add_task_header(task_header)
        self.assertNotIn(task_id, tk.supported_tasks)
        self.assertIn(task_id, tk.task_headers)

        task_header = get_task_header("abc")
        task_id2 = task_header.task_id
        task_header.fixed_header.max_price = 10.0
        tk.add_task_header(task_header)
        self.assertIn(task_id2, tk.supported_tasks)
        self.assertIn(task_id2, tk.task_headers)

        config_desc = mock.Mock()
        config_desc.min_price = 10.0
        tk.change_config(config_desc)
        self.assertNotIn(task_id, tk.supported_tasks)
        self.assertIn(task_id2, tk.supported_tasks)
        config_desc.min_price = 8.0
        tk.change_config(config_desc)
        self.assertIn(task_id, tk.supported_tasks)
        self.assertIn(task_id2, tk.supported_tasks)
        config_desc.min_price = 11.0
        tk.change_config(config_desc)
        self.assertNotIn(task_id, tk.supported_tasks)
        self.assertNotIn(task_id2, tk.supported_tasks)
        # Make sure the tasks stats are properly archived
        tar.reset_mock()
        config_desc.min_price = 9.5
        tk.change_config(config_desc)
        self.assertNotIn(task_id, tk.supported_tasks)
        self.assertIn(task_id2, tk.supported_tasks)
        tar.add_support_status.assert_any_call(
            task_id, SupportStatus(False, {UnsupportReason.MAX_PRICE: 9.0}))
        tar.add_support_status.assert_any_call(task_id2,
                                               SupportStatus(True, {}))