From 3fc80f834dbead5064bc46a2a8471d5ffefa6673 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Tue, 31 Dec 2019 12:55:09 +0100 Subject: [PATCH] New tests for worker task manager --- src/Test/TestWorkerTaskManager.py | 42 ++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/Test/TestWorkerTaskManager.py b/src/Test/TestWorkerTaskManager.py index 375100c9f..eb5c4a2a8 100644 --- a/src/Test/TestWorkerTaskManager.py +++ b/src/Test/TestWorkerTaskManager.py @@ -39,12 +39,34 @@ def testRemove(self): task = {"id": i, "priority": i % 20, "workers_num": i % 3, "inner_path": "file%s.json" % i} assert task in tasks - tasks.remove(task) + with Spy.Spy(tasks, "indexSlow") as calls: + tasks.remove(task) + assert len(calls) == 0 assert task not in tasks + # Remove non existent item + with Spy.Spy(tasks, "indexSlow") as calls: + with pytest.raises(ValueError): + tasks.remove(task) + assert len(calls) == 0 + self.checkSort(tasks) + def testRemoveAll(self): + tasks = WorkerTaskManager.WorkerTaskManager() + tasks_list = [] + for i in range(1000): + task = {"id": i, "priority": i % 20, "workers_num": i % 3, "inner_path": "file%s.json" % i} + tasks.append(task) + tasks_list.append(task) + + for task in tasks_list: + tasks.remove(task) + + assert len(tasks.inner_paths) == 0 + assert len(tasks) == 0 + def testModify(self): tasks = WorkerTaskManager.WorkerTaskManager() for i in range(1000): @@ -65,13 +87,28 @@ def testModify(self): self.checkSort(tasks) # Check reorder optimization - with Spy.Spy(tasks, "indexSlow") as calls: tasks.updateItem(task, "priority", task["priority"] + 10) assert len(calls) == 0 + with Spy.Spy(tasks, "indexSlow") as calls: + tasks.updateItem(task, "priority", task["workers_num"] - 1) + assert len(calls) == 0 + self.checkSort(tasks) + def testModifySamePriority(self): + tasks = WorkerTaskManager.WorkerTaskManager() + for i in range(1000): + tasks.append({"id": i, "priority": 10, "workers_num": 5, "inner_path": "file%s.json" % i}) + + task = tasks[333] + + # Check reorder optimization + with Spy.Spy(tasks, "indexSlow") as calls: + tasks.updateItem(task, "priority", task["workers_num"] - 1) + assert len(calls) == 0 + def testIn(self): tasks = WorkerTaskManager.WorkerTaskManager() @@ -80,7 +117,6 @@ def testIn(self): assert task not in tasks - def testFindTask(self): tasks = WorkerTaskManager.WorkerTaskManager() for i in range(1000):