Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coltmcnealy-lh committed Feb 15, 2024
1 parent 87230c3 commit 8527711
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
66 changes: 66 additions & 0 deletions server/src/test/java/e2e/InterruptLifecycleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package e2e;

import java.util.Map;

import org.junit.jupiter.api.Test;

import io.littlehorse.sdk.common.proto.LHStatus;
import io.littlehorse.sdk.wfsdk.SpawnedThreads;
import io.littlehorse.sdk.wfsdk.Workflow;
import io.littlehorse.sdk.worker.LHTaskMethod;
import io.littlehorse.test.LHTest;
import io.littlehorse.test.LHWorkflow;
import io.littlehorse.test.WorkflowVerifier;

/*
* Tests that Interrupts cause NodeRun lifecycle to move properly.
*/
@LHTest(externalEventNames = {
InterruptLifecycleTest.PARENT_EVENT,
InterruptLifecycleTest.INTERRUPT_TRIGGER,
InterruptLifecycleTest.COMPLETE_INTERRUPT_HANDLER,
InterruptLifecycleTest.CHILD_EVENT
})
public class InterruptLifecycleTest {
public static final String PARENT_EVENT = "ilt-parent-event";
public static final String CHILD_EVENT = "ilt-child-event";
public static final String INTERRUPT_TRIGGER = "ilt-interrupt-trigger";
public static final String COMPLETE_INTERRUPT_HANDLER = "ilt-complete-interrupt-handler";

@LHWorkflow("interrupt-lifecycle-test")
public Workflow interruptLifecycleTest;

private WorkflowVerifier verifier;

@Test
void shouldCompleteWithNoInterrupts() {
verifier.prepareRun(interruptLifecycleTest)
.thenSendExternalEventJsonContent(PARENT_EVENT, null)
.thenSendExternalEventJsonContent(PARENT_EVENT, null)
.waitForStatus(LHStatus.COMPLETED)
.start();
}

@LHWorkflow("interrupt-lifecycle-test")
public Workflow getInterruptLifecycleTestWf() {
return Workflow.newWorkflow("interrupt-lifecycle-test", wf -> {
wf.registerInterruptHandler(INTERRUPT_TRIGGER, handler -> {
handler.waitForEvent(COMPLETE_INTERRUPT_HANDLER);
});

wf.waitForEvent(PARENT_EVENT);
wf.sleepSeconds(1);
wf.execute("dummy-task");

// Spawn and wait for child
wf.waitForThreads(SpawnedThreads.of(wf.spawnThread(child -> {
child.waitForEvent(CHILD_EVENT);
}, "child", Map.of())));
});
}

@LHTaskMethod("dummy-task")
public String obiwan() {
return "hello there";
}
}
1 change: 1 addition & 0 deletions server/src/test/java/e2e/InterruptOnChildThreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void shouldCompleteWhenBothInterruptedChildInterruptedFirst() {
ThreadRun childInterruptThread = wfRun.getThreadRuns(2);
Assertions.assertThat(childInterruptThread.getStatus()).isNotEqualTo(LHStatus.HALTED);
})
.waitForStatus(LHStatus.COMPLETED)
.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.littlehorse.sdk.worker.LHTaskWorker;
import io.littlehorse.test.exception.LHTestExceptionUtil;
import io.littlehorse.test.exception.LHTestInitializationException;
import io.littlehorse.test.internal.ExternalTestBootstrapper;
import io.littlehorse.test.internal.StandaloneTestBootstrapper;
import io.littlehorse.test.internal.TestContext;
import java.time.Duration;
Expand All @@ -40,7 +41,7 @@ public void beforeAll(ExtensionContext context) {
getStore(context)
.getOrComputeIfAbsent(
LH_TEST_CONTEXT,
s -> new TestContext(new StandaloneTestBootstrapper(new PrincipalIdModel(getPrincipalId()))),
s -> new TestContext(new ExternalTestBootstrapper(new PrincipalIdModel(getPrincipalId()))),
TestContext.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ public WfRunVerifier thenSendExternalEventJsonContent(String externalEventName,
}

public WfRunVerifier waitForStatus(LHStatus status) {
return this.waitForStatus(status, null);
}

public WfRunVerifier waitForStatus(LHStatus status, Duration timeout) {
Function<TestExecutionContext, LHStatus> objectLHStatusFunction =
context -> lhClient.getWfRun(context.getWfRunId()).getStatus();
steps.add(new WaitForStatusStep<>(objectLHStatusFunction, status, steps.size() + 1));
steps.add(new WaitForStatusStep<>(objectLHStatusFunction, status, timeout, steps.size() + 1));
return this;
}

Expand Down

0 comments on commit 8527711

Please sign in to comment.