Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test(stepfunctions): pin that a failing Map iteration stops the .sync job of another (#4712)

mitsukado-shinagawaae710c04d040
diff --git a/docs/services/step-functions.md b/docs/services/step-functions.md
index cccfd7e92f..ebe5d0074f 100644
--- a/docs/services/step-functions.md
+++ b/docs/services/step-functions.md
@@ -110,10 +110,12 @@ When the request sets `includeExecutionData` to false, the details objects stay
A few gaps remain. `TaskStarted`, `LambdaFunctionStarted`, and `ActivityStarted` fire at
scheduling time, not when a worker actually picks up the task. `TaskSubmitted`, which real
-AWS emits for `.sync` and `.waitForTaskToken` integrations, is not emitted yet. When a
-branch fails, AWS records `*StateAborted` and `MapIterationAborted` events for the states its
-sibling branches were in; Floci cancels the siblings without recording them. A Distributed
-`Map` that declares no tolerance reports a failed item's own error rather than AWS's
+AWS emits for `.sync` and `.waitForTaskToken` integrations, is not emitted yet. When an inline
+`Map` iteration fails, AWS records a `MapIterationAborted` for each iteration it cuts and the
+`*StateAborted` of the state that iteration was in, all chained to the failing iteration's last
+event and recorded before `MapIterationFailed` and `MapStateFailed`; Floci cancels the iterations
+without recording them, where a `Parallel` records the state of each branch it cuts, as above. A
+Distributed `Map` that declares no tolerance reports a failed item's own error rather than AWS's
`States.ExceedToleratedFailureThreshold`, and emits `MapRunFailed` with that error. A `Map` that
declares one reports `States.ExceedToleratedFailureThreshold`, as AWS does.
@@ -126,7 +128,8 @@ omitted value, uses the AWS service ceiling: 40 concurrent iterations for Inline
Results remain in input order even when iterations finish out of order. If an iteration fails,
the Map state fails promptly, cancels its active sibling iterations, and does not start queued
-iterations.
+iterations. A cancelled iteration whose `Task` was waiting on a `.sync` job stops that job, the
+way a cut `Parallel` branch does.
## Distributed Map ItemReader
@@ -266,8 +269,8 @@ When the `Task`'s own clock fires, the job it was waiting on is stopped the way
ECS task reads `stopCode: UserInitiated`, the child execution reads `ABORTED` with no error, and
both carry the cause `The Task state in AWS Step Functions execution [<arn>] which was managing
this resource was aborted`. A `StopExecution` that lands while the state waits ends the wait and
-stops the job with the same cause, and so does the execution's budget, and a failure in another
-`Parallel` branch that cuts the branch the `Task` is in.
+stops the job with the same cause, and so does the execution's budget, and so does a failure in
+another branch of the `Parallel`, or in another iteration of the `Map`, that the `Task` is in.
One deviation. AWS starts the `TimeoutSeconds` clock when a worker picks the task up, the instant
it emits `ActivityStarted`. Floci emits `ActivityStarted` at schedule time, so both clocks start
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java
index fca99aee93..ca50b340f5 100644
--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorParallelCutTest.java
@@ -50,7 +50,10 @@ import static org.mockito.Mockito.when;
* cause below, and records one {@code TaskStateAborted} (or {@code WaitStateAborted}) per cut
* branch, each chained to the failing branch's last event and recorded before
* {@code ParallelStateFailed}, which is chained to that same event. When the execution's budget
- * cuts the Parallel instead, the child is aborted as well and no such event is recorded.
+ * cuts the Parallel instead, the child is aborted as well and no such event is recorded. An
+ * iteration of an inline Map that fails cuts the other iterations the same way, and the job one of
+ * them waits on is aborted too (measured: within about 0.15 s, with the same cause, whether or not
+ * a Catch on the Map keeps the execution going).
*
* <p>The failing branch pauses in a Wait that the sleeper holds until every other branch is
* parked on its own wait, so the cut always lands while the others are mid-state.
@@ -81,6 +84,16 @@ class AslExecutorParallelCutTest {
{"StartAt":"Done","States":{"Done":{"Type":"Pass","End":true}}}""";
private static final String LONG_WAIT_BRANCH = """
{"StartAt":"Long","States":{"Long":{"Type":"Wait","Seconds":20,"End":true}}}""";
+ /** An inline Map whose "fail" item runs the failing branch and whose other items run the nested one. */
+ private static final String MAP_WITH_A_FAILING_ITERATION = """
+ {"Type":"Map","End":true,"ItemProcessor":{"ProcessorConfig":{"Mode":"INLINE"},
+ "StartAt":"Route","States":{
+ "Route":{"Type":"Choice","Default":"Nest",
+ "Choices":[{"Variable":"$.kind","StringEquals":"fail","Next":"Pause"}]},
+ "Pause":{"Type":"Wait","Seconds":1,"Next":"Boom"},
+ "Boom":{"Type":"Fail","Error":"Boom","Cause":"sibling failed"},
+ "Nest":{"Type":"Task","Resource":"arn:aws:states:::states:startExecution.sync:2",
+ "Parameters":{"StateMachineArn":"%s"},"End":true}}}}""".formatted(CHILD_SM_ARN);
private final ObjectMapper objectMapper = new ObjectMapper();
private StepFunctionsService sfnService;
@@ -151,6 +164,18 @@ class AslExecutorParallelCutTest {
assertTrue(types().stream().noneMatch(type -> type.endsWith("StateAborted")), types().toString());
}
+ @Test
+ void aMapIterationFailureAbortsTheChildAnotherIterationWaitsOn() {
+ Execution execution = run(MAP_WITH_A_FAILING_ITERATION, sleeper(1), 0,
+ "[{\"kind\":\"nest\"},{\"kind\":\"fail\"}]");
+
+ assertEquals("FAILED", execution.getStatus());
+ assertEquals("Boom", execution.getError());
+ assertEquals("sibling failed", execution.getCause());
+ assertEquals(1, eventsOfType("MapIterationFailed").size(), types().toString());
+ verify(sfnService, timeout(5_000)).stopExecution(eq(CHILD_ARN), eq(ABORT_CAUSE), isNull());
+ }
+
@Test
void executionBudgetCuttingTheParallelAbortsTheChildAndRecordsNoAbortedState() {
Execution execution = run(parallel(NESTED_SYNC_BRANCH), 0, 1);
@@ -228,10 +253,15 @@ class AslExecutorParallelCutTest {
}
private Execution run(String parallelState, AslExecutor.Sleeper sleeper, int executionTimeoutSeconds) {
+ return run(parallelState, sleeper, executionTimeoutSeconds, "{}");
+ }
+
+ private Execution run(String state, AslExecutor.Sleeper sleeper, int executionTimeoutSeconds,
+ String input) {
String budget = executionTimeoutSeconds > 0
? "\"TimeoutSeconds\":%d,".formatted(executionTimeoutSeconds)
: "";
- String definition = "{" + budget + "\"StartAt\":\"P\",\"States\":{\"P\":" + parallelState + "}}";
+ String definition = "{" + budget + "\"StartAt\":\"P\",\"States\":{\"P\":" + state + "}}";
StateMachine stateMachine = new StateMachine();
stateMachine.setName("parent");
@@ -243,7 +273,7 @@ class AslExecutorParallelCutTest {
execution.setName("parent-run");
execution.setExecutionArn(PARENT_ARN);
execution.setStateMachineArn(stateMachine.getStateMachineArn());
- execution.setInput("{}");
+ execution.setInput(input);
history = new ArrayList<>();
newExecutor(sleeper).executeSync(stateMachine, execution, history, (updated, events) -> { });