@@ -191,3 +191,104 @@ func TestContinueAsNew(t *testing.T) {
191191 err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), "continue_as_new.json" )
192192 assert .ErrorContains (t , err , "missing replay decision for WorkflowExecutionContinuedAsNew" )
193193}
194+
195+ // TestSafeDeploymentVersionedWorkflow verifies that versioned workflows can be executed
196+ // safely across different versions without causing non-deterministic errors.
197+ // There are 2 workflow executions:
198+ //
199+ // * VersionedWorkflowFoo - which is the first version of the workflow which version of change id is DefaultVersion
200+ // - This workflow is supposed to execute FooActivity
201+ //
202+ // * VersionedWorkflowBar - which is the second version of the workflow which version of change id is 1
203+ // - This workflow is supposed to execute BarActivity
204+ //
205+ // There are 4 versions of the workflow:
206+ //
207+ // * VersionedWorkflowV1 - which supports only DefaultVersion and executes FooActivity
208+ // - This workflow is able to replay the history of only of VersionedWorkflowFoo
209+ //
210+ // * VersionedWorkflowV2 - which supports DefaultVersion and Version 1, and can execute FooActivity or BarActivity
211+ // - This workflow is able to replay the history of both of VersionedWorkflowFoo and VersionedWorkflowBar
212+ // - A first execution of this workflow will should execute FooActivity, because of usage workflow.ExecuteWithMinVersion(),
213+ // but the test can't check it due to Replay
214+ //
215+ // * VersionedWorkflowV3 - which supports DefaultVersion and Version 1, and can execute FooActivity or BarActivity
216+ // - This workflow is able to replay the history of both of VersionedWorkflowFoo and VersionedWorkflowBar
217+ // - A first execution of this workflow will should execute BarActivity, but the test can't check it due to Replay
218+ //
219+ // * VersionedWorkflowV4 - which supports Version 1, and can execute BarActivity
220+ // - This workflow is able to replay the history only of VersionedWorkflowBar
221+ //
222+ // So the test focusing workflows supports forward and backward compatibility of the workflows
223+ func TestVersionedWorkflows (t * testing.T ) {
224+ const (
225+ versionedWorkflowFooHistoryFile = "versioned_workflow_foo.json"
226+ versionedWorkflowBarHistoryFile = "versioned_workflow_bar.json"
227+ )
228+
229+ t .Run ("VersionedWorkflowV1" , func (t * testing.T ) {
230+ replayer := worker .NewWorkflowReplayer ()
231+ replayer .RegisterWorkflowWithOptions (VersionedWorkflowV1 , workflow.RegisterOptions {Name : versionedWorkflowName })
232+ replayer .RegisterActivityWithOptions (FooActivity , activity.RegisterOptions {Name : fooActivityName })
233+
234+ t .Run ("successfully replayed with VersionedWorkflowFoo" , func (t * testing.T ) {
235+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowFooHistoryFile )
236+ require .NoError (t , err , "Failed to replay VersionedWorkflowFoo history" )
237+ })
238+
239+ t .Run ("fail to replay with VersionedWorkflowBar" , func (t * testing.T ) {
240+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowBarHistoryFile )
241+ require .Error (t , err , "Expected to fail replaying VersionedWorkflowBar history" )
242+ })
243+ })
244+
245+ t .Run ("VersionedWorkflowV2" , func (t * testing.T ) {
246+ replayer := worker .NewWorkflowReplayer ()
247+ replayer .RegisterWorkflowWithOptions (VersionedWorkflowV2 , workflow.RegisterOptions {Name : versionedWorkflowName })
248+ replayer .RegisterActivityWithOptions (FooActivity , activity.RegisterOptions {Name : fooActivityName })
249+ replayer .RegisterActivityWithOptions (BarActivity , activity.RegisterOptions {Name : barActivityName })
250+
251+ t .Run ("successfully replayed with VersionedWorkflowFoo" , func (t * testing.T ) {
252+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowFooHistoryFile )
253+ require .NoError (t , err , "Failed to replay VersionedWorkflowFoo history" )
254+ })
255+
256+ t .Run ("successfully replayed with VersionedWorkflowBar" , func (t * testing.T ) {
257+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowBarHistoryFile )
258+ require .NoError (t , err , "Failed to replay VersionedWorkflowBar history" )
259+ })
260+ })
261+
262+ t .Run ("VersionedWorkflowV3" , func (t * testing.T ) {
263+ replayer := worker .NewWorkflowReplayer ()
264+ replayer .RegisterWorkflowWithOptions (VersionedWorkflowV3 , workflow.RegisterOptions {Name : versionedWorkflowName })
265+ replayer .RegisterActivityWithOptions (FooActivity , activity.RegisterOptions {Name : fooActivityName })
266+ replayer .RegisterActivityWithOptions (BarActivity , activity.RegisterOptions {Name : barActivityName })
267+
268+ t .Run ("successfully replayed with VersionedWorkflowFoo" , func (t * testing.T ) {
269+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowFooHistoryFile )
270+ require .NoError (t , err , "Failed to replay VersionedWorkflowFoo history" )
271+ })
272+
273+ t .Run ("successfully replayed with VersionedWorkflowBar" , func (t * testing.T ) {
274+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowBarHistoryFile )
275+ require .NoError (t , err , "Failed to replay VersionedWorkflowBar history" )
276+ })
277+ })
278+
279+ t .Run ("VersionedWorkflowV4" , func (t * testing.T ) {
280+ replayer := worker .NewWorkflowReplayer ()
281+ replayer .RegisterWorkflowWithOptions (VersionedWorkflowV4 , workflow.RegisterOptions {Name : versionedWorkflowName })
282+ replayer .RegisterActivityWithOptions (BarActivity , activity.RegisterOptions {Name : barActivityName })
283+
284+ t .Run ("fail to replay with VersionedWorkflowFoo" , func (t * testing.T ) {
285+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowFooHistoryFile )
286+ require .Error (t , err , "Expected to fail replaying VersionedWorkflowFoo history" )
287+ })
288+
289+ t .Run ("successfully replayed with VersionedWorkflowBar" , func (t * testing.T ) {
290+ err := replayer .ReplayWorkflowHistoryFromJSONFile (zaptest .NewLogger (t ), versionedWorkflowBarHistoryFile )
291+ require .NoError (t , err , "Failed to replay VersionedWorkflowBar history" )
292+ })
293+ })
294+ }
0 commit comments