def test_add_tasks(pool): dummy1 = create_dummy('dummy1') dummy2 = create_dummy('dummy2') s = sched.Sched([dummy1]) s.add_tasks([dummy2]) res = list(s.run(pool())) assert TaskRes(dummy1) in res assert TaskRes(dummy2) in res
def test_requires_provides(pool): dummy1 = create_dummy('dummy1') sched.meta.assign_val(dummy1, requires=['dep'], priority=1) dummy2 = create_dummy('dummy2') sched.meta.assign_val(dummy2, provides=['dep'], priority=2) s = sched.Sched([dummy2, dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy2), TaskRes(dummy1)]
def test_wait_for_deps(pool): # when frontline gets exhausted while there are still some tasks # to run within deps references, the planner should not exit dummy1 = create_dummy('dummy1') sched.meta.assign_val(dummy1, provides=['one']) dummy2 = create_dummy('dummy2') sched.meta.assign_val(dummy2, requires=['one'], provides=['two']) dummy3 = create_dummy('dummy3') sched.meta.assign_val(dummy3, requires=['two']) s = sched.Sched([dummy1, dummy2, dummy3]) res = list(s.run(pool(workers=4))) assert res == [TaskRes(dummy1), TaskRes(dummy2), TaskRes(dummy3)]
def test_priority(pool): dummy1 = create_dummy('dummy1') sched.meta.assign_val(dummy1, priority=3) dummy2 = create_dummy('dummy2') sched.meta.assign_val(dummy2, priority=4) s = sched.Sched([dummy2, dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy1), TaskRes(dummy2)] sched.meta.assign_val(dummy1, priority=4) sched.meta.assign_val(dummy2, priority=3) s = sched.Sched([dummy2, dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy2), TaskRes(dummy1)]
def test_shared(pool): dummy1 = create_dummy_with_shared('dummy1', 1234) sched.meta.assign_val(dummy1, requires=['dep']) dummy2 = create_dummy_with_shared('dummy2', 2345) sched.meta.assign_val(dummy2, provides=['dep']) s = sched.Sched([dummy2, dummy1]) res = list(s.run(pool())) dummy2res, dummy1res = res # order guaranteed by dep assert dummy2res == TaskRes(dummy2, shared={'dummy2': 2345}) assert dummy1res == TaskRes(dummy1, shared={ 'dummy2': 2345, 'dummy1': 1234 })
def test_shared_kwargs(pool): dummy1 = create_dummy_shared_kwargs('dummy1', 1234) args = {'testargs': 2345} sched.meta.assign_val(dummy1, kwargs=args) s = sched.Sched([dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy1, shared={'dummy1': 1234}, ret=args)]
def test_kwargs(pool): dummy1 = create_dummy_with_kwargs('dummy1') args = {'testargs': 1234} sched.meta.assign_val(dummy1, kwargs=args) s = sched.Sched([dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy1, ret=args)]
def test_claims(pool): q = mp.Queue() dummy1 = create_dummy_that_types('dummy1') sched.meta.assign_val(dummy1, claims=['res'], priority=1, kwargs={'q': q}) dummy2 = create_dummy_that_types('dummy2') sched.meta.assign_val(dummy2, claims=['res'], priority=2, kwargs={'q': q}) s = sched.Sched([dummy1, dummy2]) res = list(s.run(pool(workers=1))) assert res == [TaskRes(dummy1), TaskRes(dummy2)] output = ''.join(map(lambda x: q.get(), range(q.qsize()))) assert output == '1111122222' #s.add_tasks([dummy1, dummy2]) s = sched.Sched([dummy1, dummy2]) res = list(s.run(pool(workers=2))) assert TaskRes(dummy1) in res assert TaskRes(dummy2) in res output = ''.join(map(lambda x: str(q.get()), range(q.qsize()))) assert output == '1111122222'
def test_preset_shared(pool): dummy1 = create_dummy_with_shared('dummy1', 1234) dummy2 = create_dummy_with_shared('dummy2', 2345) s = sched.Sched([dummy1, dummy2]) s.add_shared(bothx=4444, dummy2=6666) s.add_shared(bothy=5555) res = list(s.run(pool())) assert TaskRes(dummy1, shared={ 'bothx': 4444, 'bothy': 5555, 'dummy1': 1234, 'dummy2': 6666 }) in res # pre-set 6666 was overwritten and propagated to parent assert TaskRes(dummy2, shared={ 'bothx': 4444, 'bothy': 5555, 'dummy2': 2345 }) in res
def test_task_via_init(pool): dummy1 = create_dummy('dummy1') s = sched.Sched([dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy1)]
def test_unpicklable_ret_shared_thread(pool): nonpickl = create_dummy('') dummy1 = create_dummy_with_shared('dummy1', nonpickl, ret=nonpickl) s = sched.Sched([dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy1, shared={'dummy1': nonpickl}, ret=nonpickl)]
def test_return_value(pool): dummy1 = create_dummy_with_return('dummy1', 1234) s = sched.Sched([dummy1]) res = list(s.run(pool())) assert res == [TaskRes(dummy1, ret=1234)]