Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
def test_launch_decline(mocker, python_task, offers):
    driver = mocker.Mock()
    sched = QueueScheduler(name='test-scheduler')

    sched.submit(python_task)
    sched.on_offers(driver, offers)

    calls = driver.launch.call_args_list

    args, kwargs = calls[0]
    assert isinstance(args[0], OfferID)
    assert args[0].value == 'first-offer'
    assert isinstance(args[1][0], PythonTask)
    assert args[1][0].task_id.value == 'test-task-id'

    args, kwargs = calls[1]
    assert isinstance(args[0], OfferID)
    assert args[0].value == 'second-offer'
    assert args[1] == []  # declines via launch empty task list
Example #7
0
def test_launch_decline(mocker, python_task, offers):
    driver = mocker.Mock()
    sched = QueueScheduler(name='test-scheduler')

    sched.submit(python_task)
    sched.on_offers(driver, offers)

    calls = driver.launch.call_args_list

    args, kwargs = calls[0]
    assert isinstance(args[0], OfferID)
    assert args[0].value == 'first-offer'
    assert isinstance(args[1][0], PythonTask)
    assert args[1][0].task_id.value == 'test-task-id'

    args, kwargs = calls[1]
    assert isinstance(args[0], OfferID)
    assert args[0].value == 'second-offer'
    assert args[1] == []  # declines via launch empty task list