Skip to content

Commit 1b8b155

Browse files
committed
add rebuild test, reapply test, and reset test
1 parent 03917b1 commit 1b8b155

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

service/history/ndc/events_reapplier_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
historypb "go.temporal.io/api/history/v1"
1414
"go.temporal.io/api/serviceerror"
1515
updatepb "go.temporal.io/api/update/v1"
16+
workflowpb "go.temporal.io/api/workflow/v1"
1617
enumsspb "go.temporal.io/server/api/enums/v1"
1718
persistencespb "go.temporal.io/server/api/persistence/v1"
1819
"go.temporal.io/server/common/definition"
@@ -129,6 +130,54 @@ func (s *nDCEventReapplicationSuite) TestReapplyEvents_AppliedEvent_WorkflowExec
129130
s.Equal(1, len(appliedEvent))
130131
}
131132

133+
func (s *nDCEventReapplicationSuite) TestReapplyEvents_AppliedEvent_WorkflowExecutionOptionsUpdated_WithTimeSkippingConfig() {
134+
runID := uuid.NewString()
135+
execution := &persistencespb.WorkflowExecutionInfo{
136+
NamespaceId: uuid.NewString(),
137+
}
138+
timeSkippingConfig := &workflowpb.TimeSkippingConfig{Enabled: true}
139+
event := &historypb.HistoryEvent{
140+
EventId: 1,
141+
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED,
142+
Attributes: &historypb.HistoryEvent_WorkflowExecutionOptionsUpdatedEventAttributes{
143+
WorkflowExecutionOptionsUpdatedEventAttributes: &historypb.WorkflowExecutionOptionsUpdatedEventAttributes{
144+
AttachedRequestId: "test-attached-request-id",
145+
TimeSkippingConfig: timeSkippingConfig,
146+
},
147+
},
148+
}
149+
attr := event.GetWorkflowExecutionOptionsUpdatedEventAttributes()
150+
151+
msCurrent := historyi.NewMockMutableState(s.controller)
152+
msCurrent.EXPECT().VisitUpdates(gomock.Any()).Return()
153+
msCurrent.EXPECT().GetCurrentVersion().Return(int64(0))
154+
updateRegistry := update.NewRegistry(msCurrent)
155+
msCurrent.EXPECT().IsWorkflowExecutionRunning().Return(true).Times(2)
156+
msCurrent.EXPECT().GetExecutionInfo().Return(execution).AnyTimes()
157+
msCurrent.EXPECT().AddWorkflowExecutionOptionsUpdatedEvent(
158+
attr.GetVersioningOverride(),
159+
attr.GetUnsetVersioningOverride(),
160+
attr.GetAttachedRequestId(),
161+
attr.GetAttachedCompletionCallbacks(),
162+
event.Links,
163+
attr.GetIdentity(),
164+
attr.GetPriority(),
165+
timeSkippingConfig,
166+
).Return(event, nil)
167+
msCurrent.EXPECT().HSM().Return(s.hsmNode).AnyTimes()
168+
msCurrent.EXPECT().IsWorkflowPendingOnWorkflowTaskBackoff().Return(true)
169+
dedupResource := definition.NewEventReappliedID(runID, event.GetEventId(), event.GetVersion())
170+
msCurrent.EXPECT().IsResourceDuplicated(dedupResource).Return(false)
171+
msCurrent.EXPECT().UpdateDuplicatedResource(dedupResource)
172+
events := []*historypb.HistoryEvent{
173+
{EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED},
174+
event,
175+
}
176+
appliedEvent, err := s.nDCReapplication.ReapplyEvents(context.Background(), msCurrent, updateRegistry, events, runID)
177+
s.NoError(err)
178+
s.Equal(1, len(appliedEvent))
179+
}
180+
132181
func (s *nDCEventReapplicationSuite) TestReapplyEvents_AppliedEvent_Signal() {
133182
runID := uuid.NewString()
134183
execution := &persistencespb.WorkflowExecutionInfo{

service/history/ndc/workflow_resetter_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,3 +1702,39 @@ func (s *workflowResetterSuite) TestReapplyEvents_WorkflowOptionsUpdated_Complet
17021702
s.NoError(err)
17031703
s.Empty(appliedEvents) // Event should be skipped
17041704
}
1705+
1706+
func (s *workflowResetterSuite) TestReapplyEvents_WorkflowOptionsUpdated_WithTimeSkippingConfig() {
1707+
timeSkippingConfig := &workflowpb.TimeSkippingConfig{Enabled: true}
1708+
event := &historypb.HistoryEvent{
1709+
EventId: 101,
1710+
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED,
1711+
Attributes: &historypb.HistoryEvent_WorkflowExecutionOptionsUpdatedEventAttributes{
1712+
WorkflowExecutionOptionsUpdatedEventAttributes: &historypb.WorkflowExecutionOptionsUpdatedEventAttributes{
1713+
AttachedRequestId: "test-request-id",
1714+
TimeSkippingConfig: timeSkippingConfig,
1715+
},
1716+
},
1717+
}
1718+
attr := event.GetWorkflowExecutionOptionsUpdatedEventAttributes()
1719+
1720+
ms := historyi.NewMockMutableState(s.controller)
1721+
smReg := hsm.NewRegistry()
1722+
s.NoError(workflow.RegisterStateMachine(smReg))
1723+
root, err := hsm.NewRoot(smReg, workflow.StateMachineType, nil, make(map[string]*persistencespb.StateMachineMap), nil)
1724+
s.NoError(err)
1725+
ms.EXPECT().HSM().Return(root).AnyTimes()
1726+
ms.EXPECT().AddWorkflowExecutionOptionsUpdatedEvent(
1727+
attr.GetVersioningOverride(),
1728+
attr.GetUnsetVersioningOverride(),
1729+
attr.GetAttachedRequestId(),
1730+
attr.GetAttachedCompletionCallbacks(),
1731+
event.Links,
1732+
attr.GetIdentity(),
1733+
attr.GetPriority(),
1734+
timeSkippingConfig,
1735+
).Return(&historypb.HistoryEvent{}, nil)
1736+
1737+
appliedEvents, err := reapplyEvents(context.Background(), ms, nil, smReg, []*historypb.HistoryEvent{event}, nil, "", true)
1738+
s.NoError(err)
1739+
s.Len(appliedEvents, 1)
1740+
}

service/history/workflow/mutable_state_rebuilder_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
enumspb "go.temporal.io/api/enums/v1"
1414
historypb "go.temporal.io/api/history/v1"
1515
taskqueuepb "go.temporal.io/api/taskqueue/v1"
16+
workflowpb "go.temporal.io/api/workflow/v1"
1617
enumsspb "go.temporal.io/server/api/enums/v1"
1718
historyspb "go.temporal.io/server/api/history/v1"
1819
persistencespb "go.temporal.io/server/api/persistence/v1"
@@ -2121,6 +2122,38 @@ func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowExecutionUpdateComp
21212122
s.Equal(event.TaskId, s.executionInfo.LastRunningClock)
21222123
}
21232124

2125+
func (s *stateBuilderSuite) TestApplyEvents_EventTypeWorkflowExecutionOptionsUpdated_TimeSkippingConfig() {
2126+
version := int64(1)
2127+
requestID := uuid.NewString()
2128+
execution := &commonpb.WorkflowExecution{
2129+
WorkflowId: "some random workflow ID",
2130+
RunId: tests.RunID,
2131+
}
2132+
2133+
now := time.Now().UTC()
2134+
event := &historypb.HistoryEvent{
2135+
TaskId: rand.Int63(),
2136+
Version: version,
2137+
EventId: 130,
2138+
EventTime: timestamppb.New(now),
2139+
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_OPTIONS_UPDATED,
2140+
Attributes: &historypb.HistoryEvent_WorkflowExecutionOptionsUpdatedEventAttributes{
2141+
WorkflowExecutionOptionsUpdatedEventAttributes: &historypb.WorkflowExecutionOptionsUpdatedEventAttributes{
2142+
TimeSkippingConfig: &workflowpb.TimeSkippingConfig{
2143+
Enabled: true,
2144+
},
2145+
},
2146+
},
2147+
}
2148+
s.mockMutableState.EXPECT().ApplyWorkflowExecutionOptionsUpdatedEvent(protomock.Eq(event)).Return(nil)
2149+
s.mockUpdateVersion(event)
2150+
s.mockMutableState.EXPECT().ClearStickyTaskQueue()
2151+
2152+
_, err := s.stateRebuilder.ApplyEvents(context.Background(), tests.NamespaceID, requestID, execution, s.toHistory(event), nil, "")
2153+
s.NoError(err)
2154+
s.Equal(event.TaskId, s.executionInfo.LastRunningClock)
2155+
}
2156+
21242157
func (s *stateBuilderSuite) TestApplyEvents_HSMRegistry() {
21252158
version := int64(1)
21262159
requestID := uuid.NewString()

0 commit comments

Comments
 (0)