Skip to content

Commit

Permalink
Merge branch 'fix-nested-parents' of https://github.com/littlehorse-e…
Browse files Browse the repository at this point in the history
…nterprises/littlehorse into fix-nested-parents
  • Loading branch information
bryson-g committed Feb 19, 2025
2 parents 0b79dd2 + 91d0690 commit 4da82b6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.littlehorse.common.model.getable.objectId.ExternalEventIdModel;
import io.littlehorse.common.util.LHUtil;
import io.littlehorse.sdk.common.proto.ExternalEventNodeRun;
import io.littlehorse.sdk.common.proto.LHErrorType;
import io.littlehorse.sdk.common.proto.LHStatus;
import io.littlehorse.sdk.common.proto.VariableType;
import io.littlehorse.server.streams.topology.core.ExecutionContext;
Expand Down Expand Up @@ -84,9 +85,14 @@ public ExternalEventNodeRun.Builder toProto() {
}

@Override
public boolean checkIfProcessingCompleted(ProcessorExecutionContext processorContext) {
public boolean checkIfProcessingCompleted(ProcessorExecutionContext processorContext) throws NodeFailureException {
if (externalEventId != null) return true;

if (timedOut) {
FailureModel failure = new FailureModel("ExternalEvent did not arrive in time", LHErrorType.TIMEOUT.name());
throw new NodeFailureException(failure);
}

NodeModel node = nodeRun.getNode();
ExternalEventNodeModel eNode = node.getExternalEventNode();

Expand Down Expand Up @@ -165,7 +171,6 @@ public void processExternalEventTimeout(ExternalEventTimeoutModel timeout) {
return;
}

// This is leaking the logic of the
timedOut = true;
}

Expand Down
24 changes: 24 additions & 0 deletions server/src/test/java/e2e/ExternalEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import io.littlehorse.sdk.common.proto.ExternalEvent;
import io.littlehorse.sdk.common.proto.ExternalEventDefId;
import io.littlehorse.sdk.common.proto.ExternalEventId;
import io.littlehorse.sdk.common.proto.Failure;
import io.littlehorse.sdk.common.proto.LHErrorType;
import io.littlehorse.sdk.common.proto.LHStatus;
import io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub;
import io.littlehorse.sdk.common.proto.PutExternalEventRequest;
Expand All @@ -26,6 +28,9 @@ public class ExternalEventTest {
public static final String EVT_NAME = "basic-test-event";
public static final String IGNORED_EVT_NAME = "not-a-real-event-kenobi";

@LHWorkflow("external-event-timeout")
public Workflow timeoutEvent;

@LHWorkflow("basic-external-event")
public Workflow basicExternalEvent;

Expand All @@ -41,6 +46,25 @@ public Workflow getBasicExternalEventWorkflow() {
});
}

@LHWorkflow("external-event-timeout")
public Workflow getTimeoutWorkflow() {
return Workflow.newWorkflow("external-event-timeout", wf -> {
wf.waitForEvent(EVT_NAME).timeout(1);
});
}

@Test
void shouldTimeoutIfNoEvent() {
verifier.prepareRun(timeoutEvent)
.waitForStatus(LHStatus.ERROR)
.thenVerifyNodeRun(0, 1, nodeRun -> {
Failure failure = nodeRun.getFailures(0);
Assertions.assertThat(failure.getFailureName()).isEqualTo(LHErrorType.TIMEOUT.toString());
Assertions.assertThat(failure.getMessage().toLowerCase()).contains("arrive in time");
})
.start();
}

@Test
void shouldCompleteIfEventIsSentAfterWfRunStarts() {
WfRunId id = WfRunId.newBuilder().setId(LHUtil.generateGuid()).build();
Expand Down

0 comments on commit 4da82b6

Please sign in to comment.