Skip to content

Commit

Permalink
New tests for worker task manager
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Dec 31, 2019
1 parent 20b0db7 commit 3fc80f8
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/Test/TestWorkerTaskManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()

Expand All @@ -80,7 +117,6 @@ def testIn(self):

assert task not in tasks


def testFindTask(self):
tasks = WorkerTaskManager.WorkerTaskManager()
for i in range(1000):
Expand Down

0 comments on commit 3fc80f8

Please sign in to comment.