Skip to content

Step Functions: Mock feature for StartSyncExecution #12712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

carole-lavillonniere
Copy link

Motivation

Extend the Step Functions mocking capability to support StartSyncExecution, enabling consistent testing across both Standard and Express state machines #12711

Changes

  • Apply mock config (LOCALSTACK_SFN_MOCK_CONFIG) when starting a state machine via StartSyncExecution
  • New parity test tests/aws/services/stepfunctions/v2/mocking/test_base_scenarios.py::TestBaseScenarios::test_lambda_service_invoke to verify that the mocked service integration mechanism also works when using StartSyncExecution

Testing

  1. Create an express state machine
  2. Create a mock config to mock the state machine response
  3. Start localstack with the mock configuration
  4. Start the state machine synchronously with start-execution
  5. Verify that the execution response is the expected one

TODO

  • Add a parity test tests/aws/services/stepfunctions/v2/mocking/test_base_callbacks.py::TestBaseScenarios::test_sqs_wait_for_task_token to verify that the callback mechanism (sync2) returns correctly when executed via StartSyncExecution

@localstack-bot
Copy link
Collaborator

localstack-bot commented Jun 4, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copy link
Collaborator

@localstack-bot localstack-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.

@carole-lavillonniere
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@joe4dev joe4dev added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Jun 4, 2025
@joe4dev joe4dev added this to the Playground milestone Jun 4, 2025
Copy link
Contributor

@MEPalma MEPalma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing to this feature! I’m sure users relying on mocked service integrations will find it valuable. I’ve left a few comments suggesting some possible refactoring options for your consideration.

@@ -772,6 +772,33 @@ def send_task_failure(
raise TaskDoesNotExist()
raise InvalidToken("Invalid token")

@staticmethod
def _extract_base_arn(state_machine_arn: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple types of ARNs used in Step Functions, so the term “base ARN” might be a bit misleading. It might be clearer to move the logic for stripping the mock test case name into a different function, perhaps in _get_mock_test_case below. That way, we can both reuse the logic and make its purpose more immediately clear, returning the actual state machine ARN along with the mock test case name, if present. What do you think?

@@ -889,11 +899,13 @@ def start_sync_execution(
**kwargs,
) -> StartSyncExecutionOutput:
self._validate_state_machine_arn(state_machine_arn)

base_arn = self._extract_base_arn(state_machine_arn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following from the comment above, this could be reduced to a single statement with the one on line 943 (e.g. base_arn, mock_test_case = <util>(state_machine_arn)

@@ -507,6 +509,27 @@ def launch_and_record_mocked_execution(
return execution_arn


def launch_and_record_mocked_sync_execution(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this utility!

execution_arn = launch_and_record_mocked_execution(
target_aws_client, sfn_snapshot, state_machine_arn, execution_input, test_name
)
if state_machine_type == StateMachineType.EXPRESS:
Copy link
Contributor

@MEPalma MEPalma Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are STANDARD and EXPRESS state machines. LocalStack wants to enable the mock feature for both. However, when using the StartSyncExecution API action, only EXPRESS state machines can be executed, otherwise an error is raised. This utility seems to be limited to recording the executions through StartExecution only, as it invokes the asynchronous await logic.
What do you think about reverting the changes in this function, and adding the snapshotting features for mocked executions through StartSyncExecution in your launch_and_record_mocked_sync_execution? Also considering create_and_record_express_sync_execution. This could also allow us to test for failures if a STANDARD with mocking through StartSyncExecution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants