@@ -754,6 +754,22 @@ func TestGetVersion(t *testing.T) {
754
754
res := weh .GetVersion ("test" , 1 , 3 )
755
755
assert .Equal (t , Version (2 ), res )
756
756
})
757
+ t .Run ("version exists, ExecuteWithVersion is used" , func (t * testing.T ) {
758
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
759
+ weh .changeVersions = map [string ]Version {
760
+ "test" : 2 ,
761
+ }
762
+ res := weh .GetVersion ("test" , 1 , 3 , ExecuteWithVersion (3 ))
763
+ assert .Equal (t , Version (2 ), res )
764
+ })
765
+ t .Run ("version exists, ExecuteWithMinVersion is used" , func (t * testing.T ) {
766
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
767
+ weh .changeVersions = map [string ]Version {
768
+ "test" : 2 ,
769
+ }
770
+ res := weh .GetVersion ("test" , 1 , 3 , ExecuteWithMinVersion ())
771
+ assert .Equal (t , Version (2 ), res )
772
+ })
757
773
t .Run ("version doesn't exist in replay" , func (t * testing.T ) {
758
774
weh := testWorkflowExecutionEventHandler (t , newRegistry ())
759
775
weh .isReplay = true
@@ -770,6 +786,55 @@ func TestGetVersion(t *testing.T) {
770
786
assert .Equal (t , Version (3 ), weh .changeVersions ["test" ])
771
787
assert .Equal (t , []byte (`["test-3"]` ), weh .workflowInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ], "ensure search attributes are updated" )
772
788
})
789
+ t .Run ("version doesn't exist, ExecuteWithVersion is used" , func (t * testing.T ) {
790
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
791
+ res := weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithVersion (2 ))
792
+ assert .Equal (t , Version (2 ), res )
793
+ require .Contains (t , weh .changeVersions , "test" )
794
+ assert .Equal (t , Version (2 ), weh .changeVersions ["test" ])
795
+ assert .Equal (t , []byte (`["test-2"]` ), weh .workflowInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ], "ensure search attributes are updated" )
796
+ })
797
+ t .Run ("version doesn't exist, ExecuteWithVersion is used, DefaultVersion is used" , func (t * testing.T ) {
798
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
799
+ res := weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithVersion (DefaultVersion ))
800
+ assert .Equal (t , DefaultVersion , res )
801
+ require .Contains (t , weh .changeVersions , "test" )
802
+ assert .Equal (t , DefaultVersion , weh .changeVersions ["test" ])
803
+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
804
+ })
805
+ t .Run ("version doesn't exist, ExecuteWithMinVersion is used, min is non DefaultVersion" , func (t * testing.T ) {
806
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
807
+ res := weh .GetVersion ("test" , 1 , 3 , ExecuteWithMinVersion ())
808
+ assert .Equal (t , Version (1 ), res )
809
+ require .Contains (t , weh .changeVersions , "test" )
810
+ assert .Equal (t , Version (1 ), weh .changeVersions ["test" ])
811
+ assert .Equal (t , []byte (`["test-1"]` ), weh .workflowInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ], "ensure search attributes are updated" )
812
+ })
813
+ t .Run ("version doesn't exist, ExecuteWithMinVersion is used, DefaultVersion is used" , func (t * testing.T ) {
814
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
815
+ res := weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithMinVersion ())
816
+ assert .Equal (t , DefaultVersion , res )
817
+ require .Contains (t , weh .changeVersions , "test" )
818
+ assert .Equal (t , DefaultVersion , weh .changeVersions ["test" ])
819
+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
820
+ })
821
+
822
+ t .Run ("version doesn't exist, ExecuteWithVersion is used, version > maximum version" , func (t * testing.T ) {
823
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
824
+ assert .PanicsWithValue (t , `Workflow code is too old to support version 10 for "test" changeID. The maximum supported version is 3` , func () {
825
+ weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithVersion (10 ))
826
+ })
827
+
828
+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
829
+ })
830
+ t .Run ("version doesn't exist, ExecuteWithVersion is used, version < minimum version" , func (t * testing.T ) {
831
+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
832
+ assert .PanicsWithValue (t , `Workflow code removed support of version 0. for "test" changeID. The oldest supported version is 1` , func () {
833
+ weh .GetVersion ("test" , 1 , 3 , ExecuteWithVersion (0 ))
834
+ })
835
+
836
+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
837
+ })
773
838
}
774
839
775
840
func TestMutableSideEffect (t * testing.T ) {
@@ -982,6 +1047,13 @@ func TestWorkflowExecutionEnvironment_NewTimer_immediate_calls(t *testing.T) {
982
1047
}
983
1048
984
1049
func testWorkflowExecutionEventHandler (t * testing.T , registry * registry ) * workflowExecutionEventHandlerImpl {
1050
+ var testWorkflowInfo = & WorkflowInfo {
1051
+ WorkflowType : WorkflowType {
1052
+ Name : "test" ,
1053
+ Path : "" ,
1054
+ },
1055
+ }
1056
+
985
1057
return newWorkflowExecutionEventHandler (
986
1058
testWorkflowInfo ,
987
1059
func (result []byte , err error ) {},
@@ -996,13 +1068,6 @@ func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workfl
996
1068
).(* workflowExecutionEventHandlerImpl )
997
1069
}
998
1070
999
- var testWorkflowInfo = & WorkflowInfo {
1000
- WorkflowType : WorkflowType {
1001
- Name : "test" ,
1002
- Path : "" ,
1003
- },
1004
- }
1005
-
1006
1071
func getSerializedDetails [T , V any ](t * testing.T , id T , data V ) []byte {
1007
1072
converter := defaultDataConverter {}
1008
1073
res , err := converter .ToData (id , data )
0 commit comments