Skip to content

Commit

Permalink
Fail task on unknown event when HistoryEvent.worker_may_ignore is fal…
Browse files Browse the repository at this point in the history
…se (#1363)
  • Loading branch information
Quinn-With-Two-Ns authored Jan 22, 2024
1 parent 30b2681 commit 171504d
Show file tree
Hide file tree
Showing 4 changed files with 1,029 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/internal_event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ var (
ErrMissingMarkerDetails = errors.New("marker details are nil")
// ErrMissingMarkerDataKey is returned when marker details doesn't have data key.
ErrMissingMarkerDataKey = errors.New("marker key is missing in details")
// ErrUnknownHistoryEvent is returned if there is an unknown event in history and the SDK needs to handle it
ErrUnknownHistoryEvent = errors.New("unknown history event")
)

func newWorkflowExecutionEventHandler(
Expand Down Expand Up @@ -1235,10 +1237,17 @@ func (weh *workflowExecutionEventHandlerImpl) ProcessEvent(
weh.handleWorkflowPropertiesModified(event)

default:
weh.logger.Error("unknown event type",
tagEventID, event.GetEventId(),
tagEventType, event.GetEventType().String())
// Do not fail to be forward compatible with new events
if event.WorkerMayIgnore {
// Do not fail to be forward compatible with new events
weh.logger.Debug("unknown event type",
tagEventID, event.GetEventId(),
tagEventType, event.GetEventType().String())
} else {
weh.logger.Error("unknown event type",
tagEventID, event.GetEventId(),
tagEventType, event.GetEventType().String())
return ErrUnknownHistoryEvent
}
}

if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions test/replaytests/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ func (s *replayTestSuite) TestReplayWorkflowHistoryFromFile() {
}
}

func (s *replayTestSuite) TestReplayWorkflowWithBadUnknownEvent() {
// Test replaying a history with an unknown event that cannot be ignored fails
replayer := worker.NewWorkflowReplayer()
replayer.RegisterWorkflow(Workflow1)
err := replayer.ReplayWorkflowHistoryFromJSONFile(ilog.NewDefaultLogger(), "workflow_with_bad_unknown_event.json")
require.ErrorContains(s.T(), err, "unknown history event")
}

func (s *replayTestSuite) TestReplayWorkflowWithUnknownEvent() {
// Test replaying a history with an unknown event that can be ignored does not fails
replayer := worker.NewWorkflowReplayer()
replayer.RegisterWorkflow(Workflow1)
err := replayer.ReplayWorkflowHistoryFromJSONFile(ilog.NewDefaultLogger(), "workflow_with_unknown_event.json")
require.NoError(s.T(), err)
}

func (s *replayTestSuite) TestReplayBadWorkflowHistoryFromFile() {
replayer := worker.NewWorkflowReplayer()
replayer.RegisterWorkflow(Workflow1)
Expand Down
Loading

0 comments on commit 171504d

Please sign in to comment.