예제 #1
0
def test_task_prepare():
    result = object()
    c = Callable(result=result)
    t = Task(id="task-id")
    t.prepare(c)

    status = t.getStatus()
    assert status == {
        "result": result,
        "state": {"code": 0, "message": "OK"},
        "task": {"id": "task-id", "state": "finished"}
    }
    assert c.is_finished()
예제 #2
0
파일: task_test.py 프로젝트: minqf/vdsm
def test_task_queued():
    t = Task(id="task-id")
    tm = TaskManager()
    result = object()
    c = Callable(result=result)

    # Simulate async storage APIs scheduling another function with the
    # task manager.
    def async_call():
        tm.scheduleJob(t, c)

    # Schedule job
    t.prepare(async_call)

    # Check that task is queued
    assert tm._task is t
    status = t.getStatus()
    assert status == {
        "result": "",
        "state": {
            "code": 0,
            "message": "Task is initializing"
        },
        "task": {
            "id": "task-id",
            "state": "queued"
        }
    }

    # Check that job callable was not called yet
    assert not c.is_finished()

    # Invoke the job run
    t.commit()

    # Check task final status
    status = t.getStatus()
    assert status == {
        "result": result,
        "state": {
            "code": 0,
            "message": "1 jobs completed successfully"
        },
        "task": {
            "id": "task-id",
            "state": "finished"
        }
    }

    # Check that job callable was called
    assert c.is_finished()