Skip to content

Commit dca939e

Browse files
Edward AlmondEdward Almond
authored andcommitted
Add Step Functions execution integration tests
- test_execution_pass_state: Test Pass state returns output - test_execution_choice_state: Test Choice state branches correctly - test_execution_wait_state: Test Wait state completes - test_execution_fail_state: Test Fail state fails properly - test_execution_succeed_state: Test Succeed state - test_delete_state_machine: Test state machine deletion
1 parent 6fd036c commit dca939e

1 file changed

Lines changed: 201 additions & 0 deletions

File tree

tests/integration/test_docker.py

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,207 @@ def test_describe_execution(self, client):
584584
assert "executionArn" in result
585585
assert "status" in result
586586

587+
def test_execution_pass_state(self, client):
588+
"""Test execution with Pass state that returns output."""
589+
definition = {
590+
"StartAt": "PassState",
591+
"States": {
592+
"PassState": {
593+
"Type": "Pass",
594+
"Result": {"message": "hello", "value": 42},
595+
"End": True
596+
}
597+
}
598+
}
599+
600+
client.create_state_machine(
601+
name="pass-test-sm",
602+
definition=json.dumps(definition),
603+
roleArn="arn:aws:iam::123456789012:role/test",
604+
)
605+
606+
result = client.start_execution(
607+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:pass-test-sm",
608+
input=json.dumps({"input": "data"}),
609+
)
610+
611+
exec_arn = result["executionArn"]
612+
613+
# Describe execution to get result
614+
desc = client.describe_execution(executionArn=exec_arn)
615+
616+
# Execution should complete
617+
assert desc["status"] in ["SUCCEEDED", "RUNNING"]
618+
619+
def test_execution_choice_state(self, client):
620+
"""Test execution with Choice state branches correctly."""
621+
definition = {
622+
"StartAt": "CheckValue",
623+
"States": {
624+
"CheckValue": {
625+
"Type": "Choice",
626+
"Choices": [
627+
{
628+
"Variable": "$.status",
629+
"StringEquals": "active",
630+
"Next": "ActiveState"
631+
},
632+
{
633+
"Variable": "$.status",
634+
"StringEquals": "inactive",
635+
"Next": "InactiveState"
636+
}
637+
],
638+
"Default": "UnknownState"
639+
},
640+
"ActiveState": {
641+
"Type": "Pass",
642+
"Result": {"result": "active branch"},
643+
"End": True
644+
},
645+
"InactiveState": {
646+
"Type": "Pass",
647+
"Result": {"result": "inactive branch"},
648+
"End": True
649+
},
650+
"UnknownState": {
651+
"Type": "Pass",
652+
"Result": {"result": "unknown"},
653+
"End": True
654+
}
655+
}
656+
}
657+
658+
client.create_state_machine(
659+
name="choice-test-sm",
660+
definition=json.dumps(definition),
661+
roleArn="arn:aws:iam::123456789012:role/test",
662+
)
663+
664+
# Test active branch
665+
result = client.start_execution(
666+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:choice-test-sm",
667+
input=json.dumps({"status": "active"}),
668+
)
669+
670+
desc = client.describe_execution(executionArn=result["executionArn"])
671+
assert desc["status"] in ["SUCCEEDED", "RUNNING"]
672+
673+
def test_execution_wait_state(self, client):
674+
"""Test execution with Wait state completes."""
675+
definition = {
676+
"StartAt": "WaitState",
677+
"States": {
678+
"WaitState": {
679+
"Type": "Wait",
680+
"Seconds": 1,
681+
"Next": "AfterWait"
682+
},
683+
"AfterWait": {
684+
"Type": "Pass",
685+
"Result": {"after": "wait"},
686+
"End": True
687+
}
688+
}
689+
}
690+
691+
client.create_state_machine(
692+
name="wait-test-sm",
693+
definition=json.dumps(definition),
694+
roleArn="arn:aws:iam::123456789012:role/test",
695+
)
696+
697+
result = client.start_execution(
698+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:wait-test-sm",
699+
)
700+
701+
desc = client.describe_execution(executionArn=result["executionArn"])
702+
# Should complete (wait is skipped in sync mode)
703+
assert desc["status"] in ["SUCCEEDED", "RUNNING"]
704+
705+
def test_execution_fail_state(self, client):
706+
"""Test execution with Fail state fails properly."""
707+
definition = {
708+
"StartAt": "FailState",
709+
"States": {
710+
"FailState": {
711+
"Type": "Fail",
712+
"Error": "TestError",
713+
"Cause": "This is a test failure"
714+
}
715+
}
716+
}
717+
718+
client.create_state_machine(
719+
name="fail-test-sm",
720+
definition=json.dumps(definition),
721+
roleArn="arn:aws:iam::123456789012:role/test",
722+
)
723+
724+
result = client.start_execution(
725+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:fail-test-sm",
726+
)
727+
728+
# Describe execution - should show failed status
729+
desc = client.describe_execution(executionArn=result["executionArn"])
730+
# In sync mode, execution completes immediately
731+
assert desc["status"] == "FAILED"
732+
733+
def test_execution_succeed_state(self, client):
734+
"""Test execution with Succeed state."""
735+
definition = {
736+
"StartAt": "SucceedState",
737+
"States": {
738+
"SucceedState": {
739+
"Type": "Succeed",
740+
"Output": {"result": "success"}
741+
}
742+
}
743+
}
744+
745+
client.create_state_machine(
746+
name="succeed-test-sm",
747+
definition=json.dumps(definition),
748+
roleArn="arn:aws:iam::123456789012:role/test",
749+
)
750+
751+
result = client.start_execution(
752+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:succeed-test-sm",
753+
)
754+
755+
desc = client.describe_execution(executionArn=result["executionArn"])
756+
assert desc["status"] == "SUCCEEDED"
757+
758+
def test_delete_state_machine(self, client):
759+
"""Delete a state machine."""
760+
definition = {
761+
"StartAt": "PassState",
762+
"States": {
763+
"PassState": {
764+
"Type": "Pass",
765+
"End": True
766+
}
767+
}
768+
}
769+
770+
client.create_state_machine(
771+
name="delete-test-sm",
772+
definition=json.dumps(definition),
773+
roleArn="arn:aws:iam::123456789012:role/test",
774+
)
775+
776+
# Delete
777+
client.delete_state_machine(
778+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:delete-test-sm"
779+
)
780+
781+
# Verify deleted
782+
with pytest.raises(ClientError) as exc_info:
783+
client.describe_state_machine(
784+
stateMachineArn="arn:aws:states:us-east-1:000000000000:stateMachine:delete-test-sm"
785+
)
786+
assert "StateMachineNotFound" in str(exc_info.value)
787+
587788

588789
if __name__ == "__main__":
589790
pytest.main([__file__, "-v"])

0 commit comments

Comments
 (0)