@@ -763,6 +763,83 @@ func TestGetVersion(t *testing.T) {
763763	})
764764}
765765
766+ func  TestMutableSideEffect (t  * testing.T ) {
767+ 	t .Run ("replay with existing value" , func (t  * testing.T ) {
768+ 		weh  :=  testWorkflowExecutionEventHandler (t , newRegistry ())
769+ 		weh .mutableSideEffect ["test-id" ] =  []byte (`"existing-value"` )
770+ 		weh .isReplay  =  true 
771+ 
772+ 		result  :=  weh .MutableSideEffect ("test-id" , func () interface {} {
773+ 			t .Error ("side effect function should not be called during replay with existing value" )
774+ 			return  "new-value" 
775+ 		}, func (a , b  interface {}) bool  {
776+ 			return  a  ==  b 
777+ 		})
778+ 		var  value  string 
779+ 		err  :=  result .Get (& value )
780+ 		assert .NoError (t , err )
781+ 		assert .Equal (t , "existing-value" , value )
782+ 	})
783+ 
784+ 	t .Run ("replay without existing value" , func (t  * testing.T ) {
785+ 		weh  :=  testWorkflowExecutionEventHandler (t , newRegistry ())
786+ 		weh .isReplay  =  true 
787+ 		assert .PanicsWithValue (t , "Non deterministic workflow code change detected. MutableSideEffect API call doesn't have a correspondent event in the workflow history. MutableSideEffect ID: test-id" , func () {
788+ 			weh .MutableSideEffect ("test-id" , func () interface {} {
789+ 				return  "new-value" 
790+ 			}, func (a , b  interface {}) bool  {
791+ 				return  a  ==  b 
792+ 			})
793+ 		})
794+ 	})
795+ 	t .Run ("non-replay without value" , func (t  * testing.T ) {
796+ 		weh  :=  testWorkflowExecutionEventHandler (t , newRegistry ())
797+ 
798+ 		result  :=  weh .MutableSideEffect ("test-id" , func () interface {} {
799+ 			return  "existing-value" 
800+ 		}, func (a , b  interface {}) bool  {
801+ 			return  a  ==  b 
802+ 		})
803+ 
804+ 		var  value  string 
805+ 		err  :=  result .Get (& value )
806+ 		assert .NoError (t , err )
807+ 		assert .Equal (t , "existing-value" , value )
808+ 	})
809+ 	t .Run ("non-replay with equal value" , func (t  * testing.T ) {
810+ 		weh  :=  testWorkflowExecutionEventHandler (t , newRegistry ())
811+ 		weh .mutableSideEffect ["test-id" ] =  []byte (`"existing-value"` )
812+ 
813+ 		result  :=  weh .MutableSideEffect ("test-id" , func () interface {} {
814+ 			return  "existing-value" 
815+ 		}, func (a , b  interface {}) bool  {
816+ 			return  a  ==  b 
817+ 		})
818+ 
819+ 		var  value  string 
820+ 		err  :=  result .Get (& value )
821+ 		assert .NoError (t , err )
822+ 		assert .Equal (t , "existing-value" , value )
823+ 	})
824+ 	t .Run ("non-replay with different value" , func (t  * testing.T ) {
825+ 		weh  :=  testWorkflowExecutionEventHandler (t , newRegistry ())
826+ 		weh .mutableSideEffect ["test-id" ] =  []byte (`"existing-value"` )
827+ 
828+ 		result  :=  weh .MutableSideEffect ("test-id" , func () interface {} {
829+ 			return  "new-value" 
830+ 		}, func (a , b  interface {}) bool  {
831+ 			return  a  ==  b 
832+ 		})
833+ 
834+ 		var  value  string 
835+ 		err  :=  result .Get (& value )
836+ 		assert .NoError (t , err )
837+ 		assert .Equal (t , "new-value" , value )
838+ 		// the last symbol is a control symbol, so we need to check the value without it. 
839+ 		assert .Equal (t , []byte (`"new-value"` ), weh .mutableSideEffect ["test-id" ][:len (weh .mutableSideEffect ["test-id" ])- 1 ])
840+ 	})
841+ }
842+ 
766843func  testWorkflowExecutionEventHandler (t  * testing.T , registry  * registry ) * workflowExecutionEventHandlerImpl  {
767844	return  newWorkflowExecutionEventHandler (
768845		testWorkflowInfo ,
@@ -771,7 +848,7 @@ func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workfl
771848		true ,
772849		tally .NewTestScope ("test" , nil ),
773850		registry ,
774- 		nil ,
851+ 		& defaultDataConverter {} ,
775852		nil ,
776853		opentracing.NoopTracer {},
777854		nil ,
0 commit comments