def test_task_callbacks(mocker, python_task, offers): driver = mocker.Mock() sched = QueueScheduler(name='test-scheduler') mocker.spy(python_task, 'on_update') mocker.spy(python_task, 'on_success') sched.submit(python_task) sched.on_offers(driver, offers) sched.on_update(driver, python_task.status('TASK_RUNNING')) sched.on_update(driver, python_task.status('TASK_FINISHED', data=python_task())) update_calls = python_task.on_update.call_args_list success_calls = python_task.on_success.call_args_list args, kwargs = update_calls[0] assert isinstance(args[0], PythonTaskStatus) assert args[0].state == 'TASK_RUNNING' args, kwargs = update_calls[1] assert isinstance(args[0], PythonTaskStatus) assert args[0].state == 'TASK_FINISHED' args, kwargs = success_calls[0] assert isinstance(args[0], PythonTaskStatus) assert args[0].state == 'TASK_FINISHED' assert args[0].data == 10
def test_task_result(mocker, python_task, offers): driver = mocker.Mock() sched = QueueScheduler(name='test-scheduler') result = sched.submit(python_task) sched.on_offers(driver, offers) sched.on_update(driver, python_task.status('TASK_RUNNING')) sched.on_update(driver, python_task.status('TASK_FINISHED', data=python_task())) assert result.get() == 10
def test_task_result(mocker, python_task, offers): driver = mocker.Mock() sched = QueueScheduler(name='test-scheduler') sched.submit(python_task) sched.on_offers(driver, offers) status = PythonTaskStatus(task_id=python_task.id, state='TASK_RUNNING') sched.on_update(driver, status) status = PythonTaskStatus(task_id=python_task.id, state='TASK_FINISHED', data=python_task()) sched.on_update(driver, status) assert python_task.status.state == 'TASK_FINISHED' assert python_task.status.data == 10