Пример #1
0
 def test_no_action_complete(self):
     t = quick_create(self.tid_buffer, task.Worker.NoAction,
                      task.State.Pending)
     interface.read(t.id)
     self.assertEqual(t.state, task.State.Pending)
     workers.NoAction.run(t)
     sleep(0.1)
     self.assertEqual(interface.read(t.id).state, task.State.Complete)
Пример #2
0
 def test_update(self):
     desc0 = 'test_update'
     desc1 = 'test_update_modified'
     tid = interface.create(task.Task(desc=desc0))
     tr = interface.read(tid)
     self.assertEqual(tr.desc, desc0)
     tr.desc = desc1
     interface.update(tr)
     tr2 = interface.read(tid)
     self.assertEqual(tr2.desc, desc1)
Пример #3
0
 def test_add_graph(self):
     tasks = [task.Task() for _ in range(3)]
     g = creators.task_graph(tasks, depens=[None, 0, 1])
     tids = interface.create_graph(g)
     self.assertEqual(len(tids), 3)
     tasks = [interface.read(i) for i in tids]
     tasks_root = [t for t in tasks if t.is_root]
     self.assertEqual(len(tasks_root), 1)
     task2 = tasks_root[0]
     task1 = interface.read(task2.dependency[0])
     task0 = interface.read(task1.dependency[0])
     self.assertEqual({task0.id, task1.id, task2.id}, {1, 2, 3})
Пример #4
0
def quick_create(tid_buffer, worker=None, state=None):
    if worker is None:
        worker = task.Worker.NoAction
    if state is None:
        state = task.State.Pending
    task_prot = task.Task(desc='test', state=state, worker=worker)
    tid = interface.create(task_prot)
    t = interface.read(tid)
    tid_buffer.append(tid)
    return t
Пример #5
0
def quick_create_chain(tid_buffer, states):
    tids = [quick_create(tid_buffer, s) for s in states]
    for i in range(len(tids)):
        t = interface.read(tids[i])
        t.is_root = False
        if i == len(tids) - 1:
            t.is_root = True
        if i > 0:
            t.dependency = [tids[i - 1]]
        interface.update(t)
    return tids
Пример #6
0
def get_task(id_dict, key, index=None):
    tid = id_dict[key]
    if index is not None:
        tid = tid[index]
    return interface.read(tid)
Пример #7
0
 def test_delete(self):
     tid = interface.create(task.Task())
     interface.read(tid)
     interface.delete(tid)
     with self.assertRaises(TaskNotFoundError):
         interface.read(tid)
Пример #8
0
 def test_complete(self):
     tid = interface.create(task.Task())
     interface.mark_complete(interface.read(tid))
     self.assertEqual(interface.read(tid).state, task.State.Complete)
Пример #9
0
 def test_start(self):
     tid = interface.create(task.Task())
     interface.mark_start(interface.read(tid))
     self.assertEqual(interface.read(tid).state, task.State.Runing)
Пример #10
0
 def test_init_state(self):
     tid = interface.create(task.Task())
     self.assertEqual(interface.read(tid).state,
                      task.State.BeforeSubmit)
Пример #11
0
 def test_read(self):
     tid = interface.create(task.Task(desc='test_read'))
     tr = interface.read(tid)
     self.assertEqual(tr.desc, 'test_read')