@@ -23,6 +23,7 @@ package internal
2323import (
2424 "encoding/json"
2525 "testing"
26+ "time"
2627
2728 "go.uber.org/cadence/internal/common/testlogger"
2829
@@ -68,6 +69,13 @@ func TestReplayAwareLogger(t *testing.T) {
6869 assert .NotContains (t , messages , "replay info" )
6970 assert .Contains (t , messages , "normal2 info" )
7071 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 )
7179}
7280
7381func testDecodeValueHelper (t * testing.T , env * workflowEnvironmentImpl ) {
@@ -929,6 +937,50 @@ func TestEventHandler_handleMarkerRecorded_failures(t *testing.T) {
929937 }
930938}
931939
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+
932984func testWorkflowExecutionEventHandler (t * testing.T , registry * registry ) * workflowExecutionEventHandlerImpl {
933985 return newWorkflowExecutionEventHandler (
934986 testWorkflowInfo ,
0 commit comments