mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(lambda): write the empty Result or Error wrapper when a durable step or context closes without one (#8106)
This commit is contained in:
1 parent
df1d850d71
commit
c888c636b3
3 files changed
+96
-6
No files matched your search
@@ -275,7 +275,8 @@ final class DurableCheckpointApplier {
|
||||
}
|
||||
existing.setEndTimestamp(now);
|
||||
touch(existing);
|
||||
event(existing, succeeded ? "ContextSucceeded" : "ContextFailed", resultOrError(existing));
|
||||
event(existing, succeeded ? "ContextSucceeded" : "ContextFailed",
|
||||
resultOrError(existing, !succeeded));
|
||||
}
|
||||
default -> throw invalid("Invalid action for the given operation type.");
|
||||
}
|
||||
@@ -323,7 +324,9 @@ final class DurableCheckpointApplier {
|
||||
operation.setAttempt(attempt);
|
||||
operation.setResult(update.payload());
|
||||
operation.setError(update.error());
|
||||
Map<String, Object> details = resultOrError(operation);
|
||||
boolean failed = action == DurableOperationAction.FAIL
|
||||
|| action == DurableOperationAction.RETRY && update.error() != null;
|
||||
Map<String, Object> details = resultOrError(operation, failed);
|
||||
Map<String, Object> retryDetails = new LinkedHashMap<>();
|
||||
retryDetails.put("CurrentAttempt", attempt);
|
||||
details.put("RetryDetails", retryDetails);
|
||||
@@ -342,7 +345,7 @@ final class DurableCheckpointApplier {
|
||||
operation.setStatus(DurableOperationStatus.PENDING);
|
||||
operation.setNextAttemptTimestamp(now + update.nextAttemptDelaySeconds() * 1000L);
|
||||
retryDetails.put("NextAttemptDelaySeconds", update.nextAttemptDelaySeconds());
|
||||
event(operation, update.error() != null ? "StepFailed" : "StepSucceeded", details);
|
||||
event(operation, failed ? "StepFailed" : "StepSucceeded", details);
|
||||
}
|
||||
}
|
||||
touch(operation);
|
||||
@@ -504,11 +507,11 @@ final class DurableCheckpointApplier {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> resultOrError(DurableOperation operation) {
|
||||
private static Map<String, Object> resultOrError(DurableOperation operation, boolean failed) {
|
||||
Map<String, Object> details = new LinkedHashMap<>();
|
||||
if (operation.getError() != null) {
|
||||
if (failed) {
|
||||
details.put("Error", DurableHistory.errorWrapper(operation.getError()));
|
||||
} else if (operation.getResult() != null) {
|
||||
} else {
|
||||
details.put("Result", DurableHistory.payloadWrapper(operation.getResult()));
|
||||
}
|
||||
return details;
|
||||
|
||||
@@ -182,6 +182,31 @@ class DurableCheckpointApplierTest {
|
||||
execution.getHistory().get(execution.getHistory().size() - 1).getDetails());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCloseWithoutPayloadOrErrorStillRecordsTheEmptyWrapper() {
|
||||
DurableExecution execution = execution();
|
||||
DurableCheckpointApplier.apply(execution, List.of(stepStart("s1", null), stepStart("s2", null),
|
||||
stepStart("s3", null), contextStart("c1"), contextStart("c2")), NOW, REACHABLE);
|
||||
DurableCheckpointApplier.apply(execution, List.of(
|
||||
update("s1", null, DurableOperationType.STEP, DurableOperationAction.SUCCEED, null),
|
||||
update("s2", null, DurableOperationType.STEP, DurableOperationAction.FAIL, null),
|
||||
new DurableOperationUpdate("s3", null, null, DurableOperationType.STEP, null,
|
||||
DurableOperationAction.RETRY, null, null, 1, null, null, null, null, null, null),
|
||||
update("c1", null, DurableOperationType.CONTEXT, DurableOperationAction.SUCCEED, null),
|
||||
update("c2", null, DurableOperationType.CONTEXT, DurableOperationAction.FAIL, null)), NOW, REACHABLE);
|
||||
|
||||
Map<String, Object> empty = Map.of("Truncated", false);
|
||||
List<Map<String, Object>> closes = execution.getHistory().subList(5, 10).stream()
|
||||
.map(event -> event.getDetails()).toList();
|
||||
assertEquals(List.of(
|
||||
Map.of("StepSucceededDetails", Map.of("Result", empty, "RetryDetails", Map.of("CurrentAttempt", 1))),
|
||||
Map.of("StepFailedDetails", Map.of("Error", empty, "RetryDetails", Map.of("CurrentAttempt", 1))),
|
||||
Map.of("StepSucceededDetails", Map.of("Result", empty,
|
||||
"RetryDetails", Map.of("CurrentAttempt", 1, "NextAttemptDelaySeconds", 1))),
|
||||
Map.of("ContextSucceededDetails", Map.of("Result", empty)),
|
||||
Map.of("ContextFailedDetails", Map.of("Error", empty))), closes);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRejectedBatchLeavesTheExecutionUntouched() {
|
||||
DurableExecution execution = execution();
|
||||
@@ -227,6 +252,10 @@ class DurableCheckpointApplierTest {
|
||||
return update(id, parentId, DurableOperationType.STEP, DurableOperationAction.START, null);
|
||||
}
|
||||
|
||||
private static DurableOperationUpdate contextStart(String id) {
|
||||
return update(id, null, DurableOperationType.CONTEXT, DurableOperationAction.START, null);
|
||||
}
|
||||
|
||||
private static DurableOperationUpdate waitStart(String id) {
|
||||
return new DurableOperationUpdate(id, null, null, DurableOperationType.WAIT, null, DurableOperationAction.START,
|
||||
null, null, null, 5, null, null, null, null, null);
|
||||
|
||||
+58
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -195,6 +196,51 @@ class LambdaDurableProtocolIntegrationTest {
|
||||
.body("DurableExecutionArn", equalTo(arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCloseWithoutPayloadOrErrorKeepsTheEmptyWrapperInTheHistory() throws Exception {
|
||||
CompletableFuture<Response> invoke = CompletableFuture.supplyAsync(() -> given()
|
||||
.header("X-Amz-Durable-Execution-Name", "empty-close-1")
|
||||
.body("{}")
|
||||
.post(LAMBDA + "/functions/" + FUNCTION + ":$LATEST/invocations"));
|
||||
|
||||
Invocation invocation = invoker.awaitInvocation(Duration.ofSeconds(30));
|
||||
JsonNode event = MAPPER.readTree(invocation.payload());
|
||||
String arn = event.get("DurableExecutionArn").asText();
|
||||
String token = checkpoint(arn, event.get("CheckpointToken").asText(), """
|
||||
{"Id": "s1", "Type": "STEP", "SubType": "Step", "Action": "START"},
|
||||
{"Id": "c1", "Type": "CONTEXT", "SubType": "RunInChildContext", "Action": "START"}
|
||||
""");
|
||||
token = checkpoint(arn, token, """
|
||||
{"Id": "s1", "Type": "STEP", "SubType": "Step", "Action": "FAIL"},
|
||||
{"Id": "c1", "Type": "CONTEXT", "SubType": "RunInChildContext", "Action": "SUCCEED"}
|
||||
""");
|
||||
checkpoint(arn, token, """
|
||||
{"Id": "x", "Type": "EXECUTION", "Action": "SUCCEED", "Payload": "\\"done\\""}
|
||||
""");
|
||||
invocation.response().complete(handlerResponse("{\"Status\": \"SUCCEEDED\"}"));
|
||||
assertEquals(200, invoke.get(30, TimeUnit.SECONDS).statusCode());
|
||||
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.get(DURABLE + "/durable-executions/" + arn + "/history?IncludeExecutionData=true")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Events[3].EventType", equalTo("StepFailed"))
|
||||
.body("Events[3].StepFailedDetails.Error", equalTo(Map.of("Truncated", false)))
|
||||
.body("Events[4].EventType", equalTo("ContextSucceeded"))
|
||||
.body("Events[4].ContextSucceededDetails.Result", equalTo(Map.of("Truncated", false)));
|
||||
|
||||
given()
|
||||
.urlEncodingEnabled(false)
|
||||
.when()
|
||||
.get(DURABLE + "/durable-executions/" + arn + "/history")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Events[3].StepFailedDetails.Error", equalTo(Map.of("Truncated", true)))
|
||||
.body("Events[4].ContextSucceededDetails.Result", equalTo(Map.of("Truncated", true)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anAsynchronousInvokeIsIdempotentByNameAndCanBeStopped() throws Exception {
|
||||
Response accepted = given()
|
||||
@@ -488,6 +534,18 @@ class LambdaDurableProtocolIntegrationTest {
|
||||
second.response().complete(handlerResponse("{\"Status\": \"SUCCEEDED\", \"Result\": \"\\\"ok\\\"\"}"));
|
||||
}
|
||||
|
||||
private static String checkpoint(String arn, String token, String updates) {
|
||||
return given()
|
||||
.urlEncodingEnabled(false)
|
||||
.contentType("application/json")
|
||||
.body("{\"CheckpointToken\": \"" + token + "\", \"Updates\": [" + updates + "]}")
|
||||
.when()
|
||||
.post(DURABLE + "/durable-executions/" + arn + "/checkpoint")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().jsonPath().getString("CheckpointToken");
|
||||
}
|
||||
|
||||
private static DurableInvocationResult handlerResponse(String json) {
|
||||
return new DurableInvocationResult("req-" + System.nanoTime(), json.getBytes(StandardCharsets.UTF_8), null);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user