Skip to content
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

fix(server): external-event timeout #1313

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading