New tests for worker task manager

This commit is contained in:
shortcutme 2019-12-31 12:55:09 +01:00
parent 20b0db7ddb
commit 3fc80f834d
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -39,12 +39,34 @@ class TestUiWebsocket:
task = {"id": i, "priority": i % 20, "workers_num": i % 3, "inner_path": "file%s.json" % i} task = {"id": i, "priority": i % 20, "workers_num": i % 3, "inner_path": "file%s.json" % i}
assert task in tasks 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 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) 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): def testModify(self):
tasks = WorkerTaskManager.WorkerTaskManager() tasks = WorkerTaskManager.WorkerTaskManager()
for i in range(1000): for i in range(1000):
@ -65,13 +87,28 @@ class TestUiWebsocket:
self.checkSort(tasks) self.checkSort(tasks)
# Check reorder optimization # Check reorder optimization
with Spy.Spy(tasks, "indexSlow") as calls: with Spy.Spy(tasks, "indexSlow") as calls:
tasks.updateItem(task, "priority", task["priority"] + 10) tasks.updateItem(task, "priority", task["priority"] + 10)
assert len(calls) == 0 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) 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): def testIn(self):
tasks = WorkerTaskManager.WorkerTaskManager() tasks = WorkerTaskManager.WorkerTaskManager()
@ -80,7 +117,6 @@ class TestUiWebsocket:
assert task not in tasks assert task not in tasks
def testFindTask(self): def testFindTask(self):
tasks = WorkerTaskManager.WorkerTaskManager() tasks = WorkerTaskManager.WorkerTaskManager()
for i in range(1000): for i in range(1000):