Hello,
I’m looking for guidance on how to write integration tests that cover old versions of a workflow, specifically in the Java SDK.
We currently use Workflow Replayer tests frequently to validate old versions, but they are not helpful for all scenarios.
Example Scenario:
Let’s say this was the original version of our workflow:
MyWorkflow {
step1();
step2();
step3();
step4();
}
Now, we’ve updated the workflow as follows:
MyWorkflow {
int version = Workflow.getVersion("change", Workflow.DEFAULT_VERSION, 1);
if (version == Workflow.DEFAULT_VERSION) {
step1();
step2();
step3();
step4();
} else {
step1New();
step2New();
step3New();
step4New();
step5();
}
}
I want to ensure that existing workflow runs (which started with the old code) continue executing the old logic, regardless of code changes.
The Problem:
Currently, integration tests always run the latest version of the workflow. I need a way to write tests that specifically execute the old code path.
Here’s a concrete example of where Replayer tests fall short:
Suppose we have a workflow (RunId: 1) running on the old version and it is currently paused at step2()
. While updating the code, I mistakenly introduce a bug and omit step4()
from the old version logic:
MyWorkflow {
int version = Workflow.getVersion("change", Workflow.DEFAULT_VERSION, 1);
if (version == Workflow.DEFAULT_VERSION) {
step1();
step2();
step3(); // step4() mistakenly removed!
} else {
step1New();
step2New();
step3New();
step4New();
step5();
}
}
This change is incorrect, but Replayer tests will not catch it because they only verify that the history can be replayed—they do not ensure that the old logic is still intact.
Question:
Is there any way to write integration tests that explicitly test the old version path of a workflow (i.e., where Workflow.getVersion(...)
returns DEFAULT_VERSION
)?
Ideally, I’d like to be able to mock or force Workflow.getVersion
to return the old version, but that doesn’t seem currently possible.
How do others handle this kind of testing, especially when ensuring that older, in-progress workflows continue to function correctly after workflow updates?
Thanks in advance!