Skip to content

Commit 77d52be

Browse files
committed
Add a few tests
1 parent 06afa1f commit 77d52be

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

internal/internal_event_handlers.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,6 @@ func (wc *workflowEnvironmentImpl) GenerateSequence() int32 {
463463
return result
464464
}
465465

466-
func (wc *workflowEnvironmentImpl) CreateNewDecision(decisionType m.DecisionType) *m.Decision {
467-
return &m.Decision{
468-
DecisionType: common.DecisionTypePtr(decisionType),
469-
}
470-
}
471-
472466
func (wc *workflowEnvironmentImpl) ExecuteActivity(parameters executeActivityParams, callback resultHandler) *activityInfo {
473467
scheduleTaskAttr := &m.ScheduleActivityTaskDecisionAttributes{}
474468
if parameters.ActivityID == nil || *parameters.ActivityID == "" {

internal/internal_event_handlers_test.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ package internal
2222

2323
import (
2424
"encoding/json"
25-
"testing"
26-
2725
"go.uber.org/cadence/internal/common/testlogger"
26+
"testing"
27+
"time"
2828

2929
"github.com/opentracing/opentracing-go"
3030
"github.com/uber-go/tally"
@@ -68,6 +68,13 @@ func TestReplayAwareLogger(t *testing.T) {
6868
assert.NotContains(t, messages, "replay info")
6969
assert.Contains(t, messages, "normal2 info")
7070
assert.Contains(t, messages, "replay2 info")
71+
72+
isReplay = true
73+
enableLoggingInReplay = true
74+
parentCore := wrapLogger(&isReplay, &enableLoggingInReplay)
75+
wrappedCore := parentCore(core).With([]zapcore.Field{zap.String("key", "value")}).(*replayAwareZapCore)
76+
assert.Equal(t, wrappedCore.isReplay, &isReplay)
77+
assert.Equal(t, wrappedCore.enableLoggingInReplay, &enableLoggingInReplay)
7178
}
7279

7380
func testDecodeValueHelper(t *testing.T, env *workflowEnvironmentImpl) {
@@ -929,6 +936,50 @@ func TestEventHandler_handleMarkerRecorded_failures(t *testing.T) {
929936
}
930937
}
931938

939+
func TestWorkflowEnvironment_sessions(t *testing.T) {
940+
handler := testWorkflowExecutionEventHandler(t, newRegistry())
941+
testSession := &SessionInfo{
942+
SessionID: "test-session",
943+
HostName: "test-host",
944+
}
945+
handler.AddSession(testSession)
946+
list := handler.getOpenSessions()
947+
assert.Contains(t, list, testSession)
948+
handler.RemoveSession(testSession.SessionID)
949+
list = handler.getOpenSessions()
950+
assert.Empty(t, list)
951+
}
952+
953+
func TestWorkflowExecutionEnvironment_NewTimer_immediate_calls(t *testing.T) {
954+
t.Run("immediate call", func(t *testing.T) {
955+
handler := testWorkflowExecutionEventHandler(t, newRegistry())
956+
handlerCalled := false
957+
res := handler.NewTimer(0, func(result []byte, err error) {
958+
assert.NoError(t, err)
959+
handlerCalled = true
960+
})
961+
assert.True(t, handlerCalled, "handler must be called immediately")
962+
assert.Nil(t, res)
963+
})
964+
t.Run("negative duration", func(t *testing.T) {
965+
handler := testWorkflowExecutionEventHandler(t, newRegistry())
966+
handlerCalled := false
967+
res := handler.NewTimer(-2*time.Second, func(result []byte, err error) {
968+
handlerCalled = true
969+
assert.ErrorContains(t, err, "negative duration provided")
970+
})
971+
assert.Nil(t, res)
972+
assert.True(t, handlerCalled, "handler must be called immediately")
973+
})
974+
t.Run("timer cancellation", func(t *testing.T) {
975+
handler := testWorkflowExecutionEventHandler(t, newRegistry())
976+
timer := handler.NewTimer(time.Second, func(result []byte, err error) {
977+
assert.ErrorIs(t, err, ErrCanceled)
978+
})
979+
handler.RequestCancelTimer(timer.timerID)
980+
})
981+
}
982+
932983
func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workflowExecutionEventHandlerImpl {
933984
return newWorkflowExecutionEventHandler(
934985
testWorkflowInfo,

0 commit comments

Comments
 (0)