File: test_stepfunctions_idempotency.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (69 lines) | stat: -rw-r--r-- 2,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from unittest import SkipTest

import pytest
from botocore.exceptions import ClientError

from moto import settings

from . import (
    allow_aws_request,
    aws_verified,
    verify_execution_result,
)


@aws_verified
@pytest.mark.aws_verified
def test_create_state_machine_twice_after_failure():
    if settings.TEST_SERVER_MODE:
        raise SkipTest("Don't need to test this in ServerMode")

    def _verify_result(client, execution, execution_arn):
        name = execution["name"]
        arn = execution["stateMachineArn"]
        execution_arn = execution["executionArn"]

        # Execution fails if we re-start it after failure
        with pytest.raises(ClientError) as exc:
            client.start_execution(name=name, stateMachineArn=arn)
        err = exc.value.response["Error"]
        assert err["Code"] == "ExecutionAlreadyExists"
        assert err["Message"] == f"Execution Already Exists: '{execution_arn}'"

    verify_execution_result(_verify_result, "FAILED", "failure")


@aws_verified
@pytest.mark.aws_verified
def test_create_state_machine_twice_after_success():
    if settings.TEST_SERVER_MODE:
        raise SkipTest("Don't need to test this in ServerMode")

    def _verify_result(client, execution, execution_arn):
        name = execution["name"]
        arn = execution["stateMachineArn"]
        execution_arn = execution["executionArn"]

        if execution["status"] == "RUNNING":
            # We can start the execution just fine
            idempotent = client.start_execution(name=name, stateMachineArn=arn)
            assert idempotent["executionArn"] == execution_arn

            # We're not done yet - we should check in on the progress later
            return False
        elif execution["status"] == "SUCCEEDED":
            # Execution fails if we re-start it after it finishes
            with pytest.raises(ClientError) as exc:
                client.start_execution(name=name, stateMachineArn=arn)
            err = exc.value.response["Error"]
            assert err["Code"] == "ExecutionAlreadyExists"
            assert err["Message"] == f"Execution Already Exists: '{execution_arn}'"

            # Execution finished, and we verified our error exception
            # Return True to indicate we can tear down our StateMachine
            return True

    # AWS is a little slower, so we need to wait longer
    # If we only wait 1 second, our execution might finish before we can retry it
    tmpl_name = "wait_15" if allow_aws_request() else "wait_1"
    verify_execution_result(_verify_result, None, tmpl_name)