@@ -23,6 +23,7 @@ package internal
23
23
import (
24
24
"encoding/json"
25
25
"testing"
26
+ "time"
26
27
27
28
"go.uber.org/cadence/internal/common/testlogger"
28
29
@@ -68,6 +69,13 @@ func TestReplayAwareLogger(t *testing.T) {
68
69
assert .NotContains (t , messages , "replay info" )
69
70
assert .Contains (t , messages , "normal2 info" )
70
71
assert .Contains (t , messages , "replay2 info" )
72
+
73
+ isReplay = true
74
+ enableLoggingInReplay = true
75
+ parentCore := wrapLogger (& isReplay , & enableLoggingInReplay )
76
+ wrappedCore := parentCore (core ).With ([]zapcore.Field {zap .String ("key" , "value" )}).(* replayAwareZapCore )
77
+ assert .Equal (t , wrappedCore .isReplay , & isReplay )
78
+ assert .Equal (t , wrappedCore .enableLoggingInReplay , & enableLoggingInReplay )
71
79
}
72
80
73
81
func testDecodeValueHelper (t * testing.T , env * workflowEnvironmentImpl ) {
@@ -929,6 +937,50 @@ func TestEventHandler_handleMarkerRecorded_failures(t *testing.T) {
929
937
}
930
938
}
931
939
940
+ func TestWorkflowEnvironment_sessions (t * testing.T ) {
941
+ handler := testWorkflowExecutionEventHandler (t , newRegistry ())
942
+ testSession := & SessionInfo {
943
+ SessionID : "test-session" ,
944
+ HostName : "test-host" ,
945
+ }
946
+ handler .AddSession (testSession )
947
+ list := handler .getOpenSessions ()
948
+ assert .Contains (t , list , testSession )
949
+ handler .RemoveSession (testSession .SessionID )
950
+ list = handler .getOpenSessions ()
951
+ assert .Empty (t , list )
952
+ }
953
+
954
+ func TestWorkflowExecutionEnvironment_NewTimer_immediate_calls (t * testing.T ) {
955
+ t .Run ("immediate call" , func (t * testing.T ) {
956
+ handler := testWorkflowExecutionEventHandler (t , newRegistry ())
957
+ handlerCalled := false
958
+ res := handler .NewTimer (0 , func (result []byte , err error ) {
959
+ assert .NoError (t , err )
960
+ handlerCalled = true
961
+ })
962
+ assert .True (t , handlerCalled , "handler must be called immediately" )
963
+ assert .Nil (t , res )
964
+ })
965
+ t .Run ("negative duration" , func (t * testing.T ) {
966
+ handler := testWorkflowExecutionEventHandler (t , newRegistry ())
967
+ handlerCalled := false
968
+ res := handler .NewTimer (- 2 * time .Second , func (result []byte , err error ) {
969
+ handlerCalled = true
970
+ assert .ErrorContains (t , err , "negative duration provided" )
971
+ })
972
+ assert .Nil (t , res )
973
+ assert .True (t , handlerCalled , "handler must be called immediately" )
974
+ })
975
+ t .Run ("timer cancellation" , func (t * testing.T ) {
976
+ handler := testWorkflowExecutionEventHandler (t , newRegistry ())
977
+ timer := handler .NewTimer (time .Second , func (result []byte , err error ) {
978
+ assert .ErrorIs (t , err , ErrCanceled )
979
+ })
980
+ handler .RequestCancelTimer (timer .timerID )
981
+ })
982
+ }
983
+
932
984
func testWorkflowExecutionEventHandler (t * testing.T , registry * registry ) * workflowExecutionEventHandlerImpl {
933
985
return newWorkflowExecutionEventHandler (
934
986
testWorkflowInfo ,
0 commit comments