def test_task_is_running_false(self): """Test that a task is not running.""" task_list = [1, 2, 3] _cache = WorkerCache() _cache.set_host_specific_task_list(task_list) self.assertFalse(_cache.task_is_running(4))
def test_remove_task_from_cache_value_not_in_cache(self): """Test that a task is removed.""" task_list = [1, 2, 3, 4] _cache = WorkerCache() _cache.set_host_specific_task_list(task_list) self.assertEqual(_cache.host_specific_worker_cache, task_list) _cache.remove_task_from_cache(5) self.assertEqual(_cache.host_specific_worker_cache, task_list)
def test_set_host_specific_task_list(self): """Test that setting a task list works.""" task_list = [1, 2, 3] _cache = WorkerCache() self.assertEqual(_cache.host_specific_worker_cache, []) _cache.set_host_specific_task_list(task_list) self.assertEqual(_cache.host_specific_worker_cache, task_list)
def test_remove_task_from_cache(self): """Test that a task is removed.""" task_list = [1, 2, 3, 4] expected = [1, 2, 3] _cache = WorkerCache() _cache.set_host_specific_task_list(task_list) self.assertEqual(_cache.host_specific_worker_cache, task_list) _cache.remove_task_from_cache(4) self.assertEqual(_cache.host_specific_worker_cache, expected)
def test_add_task_to_cache(self): """Test that a single task is added.""" task_list = [1, 2, 3] expected = [1, 2, 3, 4] _cache = WorkerCache() _cache.set_host_specific_task_list(task_list) self.assertEqual(_cache.host_specific_worker_cache, task_list) _cache.add_task_to_cache(4) self.assertEqual(_cache.host_specific_worker_cache, expected)
def test_invalidate_host(self): """Test that a host's cache is invalidated.""" task_list = [1, 2, 3] _cache = WorkerCache() _cache.set_host_specific_task_list(task_list) self.assertEqual(_cache.host_specific_worker_cache, task_list) _cache.invalidate_host() self.assertEqual(_cache.host_specific_worker_cache, [])
def test_get_all_running_tasks(self): """Test that multiple hosts' task lists are combined.""" second_host = "test" first_host_list = [1, 2, 3] second_host_list = [4, 5, 6] expected = first_host_list + second_host_list _cache = WorkerCache() _cache.set_host_specific_task_list(first_host_list) _worker_cache = _cache.worker_cache _worker_cache[second_host] = [4, 5, 6] cache.set(settings.WORKER_CACHE_KEY, _worker_cache, timeout=None) self.assertEqual(_cache.get_all_running_tasks(), expected)