diff --git a/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/vm/UpdateLocalsCommand.java b/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/vm/UpdateLocalsCommand.java index 75eed75fd2..75762b4a67 100644 --- a/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/vm/UpdateLocalsCommand.java +++ b/runtime/v2/runner/src/main/java/com/walmartlabs/concord/runtime/v2/runner/vm/UpdateLocalsCommand.java @@ -29,11 +29,12 @@ import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Map; /** * Takes the input, interpolates its values and sets the result - * as the current frame's local variables. + * to all root frame's local variables. *

* Optionally takes a list of threads which root frames should be * updated with provided variables. @@ -86,8 +87,13 @@ public void eval(Runtime runtime, State state, ThreadId threadId) { Map m = ee.evalAsMap(ecf.scope(ctx), input); for (ThreadId tid : threads) { - Frame root = VMUtils.assertNearestRoot(state, tid); - VMUtils.putLocals(root, m); + List frames = state.getFrames(tid); + + for (Frame f : frames) { + if (f.getType() == FrameType.ROOT) { + VMUtils.putLocals(f, m); + } + } } } } diff --git a/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/MainTest.java b/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/MainTest.java index 2dea429329..b804e05c10 100644 --- a/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/MainTest.java +++ b/runtime/v2/runner/src/test/java/com/walmartlabs/concord/runtime/v2/runner/MainTest.java @@ -184,6 +184,37 @@ public void tearDown() throws IOException { LoggingConfigurator.reset(); } + @Test + public void testVariablesAfterResume() throws Exception { + deploy("variablesAfterResume"); + + save(ProcessConfiguration.builder() + .build()); + + byte[] log = run(); + assertLog(log, ".*workDir1: " + workDir.toAbsolutePath() + ".*"); + assertLog(log, ".*workDir3: " + workDir.toAbsolutePath() + ".*"); + + List

forms = formService.list(); + assertEquals(1, forms.size()); + + Form myForm = forms.get(0); + assertEquals("myForm", myForm.name()); + + // resume the process using the saved form + + Map data = new HashMap<>(); + data.put("fullName", "John Smith"); + + Path newWorkDir = Files.createTempDirectory("test-new"); + IOUtils.copy(workDir, newWorkDir); + workDir = newWorkDir; + + log = resume(myForm.eventName(), ProcessConfiguration.builder().arguments(Collections.singletonMap("myForm", data)).build()); + assertLog(log, ".*workDir4: " + workDir.toAbsolutePath() + ".*"); + assertLog(log, ".*workDir2: " + workDir.toAbsolutePath() + ".*"); + } + @Test public void test() throws Exception { deploy("hello"); diff --git a/runtime/v2/runner/src/test/resources/com/walmartlabs/concord/runtime/v2/runner/variablesAfterResume/concord.yaml b/runtime/v2/runner/src/test/resources/com/walmartlabs/concord/runtime/v2/runner/variablesAfterResume/concord.yaml new file mode 100644 index 0000000000..a9f632a096 --- /dev/null +++ b/runtime/v2/runner/src/test/resources/com/walmartlabs/concord/runtime/v2/runner/variablesAfterResume/concord.yaml @@ -0,0 +1,19 @@ +configuration: + runtime: concord-v2 + +flows: + default: + - log: "workDir1: ${workDir}" + + - call: inner + + - log: "workDir2: ${workDir}" + + inner: + - log: "workDir3: ${workDir}" + - form: myForm + - log: "workDir4: ${workDir}" + +forms: + myForm: + - fullName: { label: "Name", type: "string", placeholder: "Place name here" }