def test_workflow_execution_schedule_activity_task_without_task_list_should_take_default(
):
    wfe = make_workflow_execution()
    wfe.domain.add_type(
        ActivityType("test-activity", "v1.2", task_list="foobar"))
    wfe.schedule_activity_task(
        123,
        {
            "activityId": "my-activity-001",
            "activityType": {
                "name": "test-activity",
                "version": "v1.2"
            },
            "scheduleToStartTimeout": "600",
            "scheduleToCloseTimeout": "600",
            "startToCloseTimeout": "600",
            "heartbeatTimeout": "300",
        },
    )

    wfe.open_counts["openActivityTasks"].should.equal(1)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ActivityTaskScheduled")
    last_event.event_attributes["taskList"]["name"].should.equal("foobar")

    task = wfe.activity_tasks[0]
    wfe.domain.activity_task_lists["foobar"].should.contain(task)
Exemple #2
0
def test_activity_task_full_dict_representation():
    wfe = make_workflow_execution()
    at = ActivityTask(
        activity_id="my-activity-123",
        activity_type=ActivityType("foo", "v1.0"),
        input="optional",
        scheduled_event_id=117,
        timeouts=ACTIVITY_TASK_TIMEOUTS,
        workflow_execution=wfe,
    )
    at.start(1234)

    fd = at.to_full_dict()
    fd["activityId"].should.equal("my-activity-123")
    fd["activityType"]["version"].should.equal("v1.0")
    fd["input"].should.equal("optional")
    fd["startedEventId"].should.equal(1234)
    fd.should.contain("taskToken")
    fd["workflowExecution"].should.equal(wfe.to_short_dict())

    at.start(1234)
    fd = at.to_full_dict()
    fd["startedEventId"].should.equal(1234)
Exemple #3
0
def make_workflow_execution(**kwargs):
    domain = get_basic_domain()
    domain.add_type(ActivityType("test-activity", "v1.1"))
    wft = get_basic_workflow_type()
    return WorkflowExecution(domain, wft, "ab1234", **kwargs)
def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attributes(
):
    wfe = make_workflow_execution()
    at = ActivityType("test-activity", "v1.1")
    at.status = "DEPRECATED"
    wfe.domain.add_type(at)
    wfe.domain.add_type(ActivityType("test-activity", "v1.2"))

    hsh = {
        "activityId": "my-activity-001",
        "activityType": {
            "name": "test-activity-does-not-exists",
            "version": "v1.1"
        },
    }

    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "ACTIVITY_TYPE_DOES_NOT_EXIST")

    hsh["activityType"]["name"] = "test-activity"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "ACTIVITY_TYPE_DEPRECATED")

    hsh["activityType"]["version"] = "v1.2"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "DEFAULT_TASK_LIST_UNDEFINED")

    hsh["taskList"] = {"name": "foobar"}
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "DEFAULT_SCHEDULE_TO_START_TIMEOUT_UNDEFINED")

    hsh["scheduleToStartTimeout"] = "600"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "DEFAULT_SCHEDULE_TO_CLOSE_TIMEOUT_UNDEFINED")

    hsh["scheduleToCloseTimeout"] = "600"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "DEFAULT_START_TO_CLOSE_TIMEOUT_UNDEFINED")

    hsh["startToCloseTimeout"] = "600"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal(
        "DEFAULT_HEARTBEAT_TIMEOUT_UNDEFINED")

    wfe.open_counts["openActivityTasks"].should.equal(0)
    wfe.activity_tasks.should.have.length_of(0)
    wfe.domain.activity_task_lists.should.have.length_of(0)

    hsh["heartbeatTimeout"] = "300"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ActivityTaskScheduled")

    task = wfe.activity_tasks[0]
    wfe.domain.activity_task_lists["foobar"].should.contain(task)
    wfe.open_counts["openDecisionTasks"].should.equal(0)
    wfe.open_counts["openActivityTasks"].should.equal(1)
def test_workflow_execution_schedule_activity_task_should_fail_if_wrong_attributes():
    wfe = make_workflow_execution()
    at = ActivityType("test-activity", "v1.1")
    at.status = "DEPRECATED"
    wfe.domain.add_type(at)
    wfe.domain.add_type(ActivityType("test-activity", "v1.2"))

    hsh = {
        "activityId": "my-activity-001",
        "activityType": {"name": "test-activity-does-not-exists", "version": "v1.1"},
    }

    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("ACTIVITY_TYPE_DOES_NOT_EXIST")

    hsh["activityType"]["name"] = "test-activity"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("ACTIVITY_TYPE_DEPRECATED")

    hsh["activityType"]["version"] = "v1.2"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("DEFAULT_TASK_LIST_UNDEFINED")

    hsh["taskList"] = {"name": "foobar"}
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("DEFAULT_SCHEDULE_TO_START_TIMEOUT_UNDEFINED")

    hsh["scheduleToStartTimeout"] = "600"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("DEFAULT_SCHEDULE_TO_CLOSE_TIMEOUT_UNDEFINED")

    hsh["scheduleToCloseTimeout"] = "600"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("DEFAULT_START_TO_CLOSE_TIMEOUT_UNDEFINED")

    hsh["startToCloseTimeout"] = "600"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ScheduleActivityTaskFailed")
    last_event.event_attributes["cause"].should.equal("DEFAULT_HEARTBEAT_TIMEOUT_UNDEFINED")

    wfe.open_counts["openActivityTasks"].should.equal(0)
    wfe.activity_tasks.should.have.length_of(0)
    wfe.domain.activity_task_lists.should.have.length_of(0)

    hsh["heartbeatTimeout"] = "300"
    wfe.schedule_activity_task(123, hsh)
    last_event = wfe.events()[-1]
    last_event.event_type.should.equal("ActivityTaskScheduled")

    task = wfe.activity_tasks[0]
    wfe.domain.activity_task_lists["foobar"].should.contain(task)
    wfe.open_counts["openDecisionTasks"].should.equal(0)
    wfe.open_counts["openActivityTasks"].should.equal(1)