Skip to content

Commit 6e84b74

Browse files
committed
Relax stamp validation for legacy activity tasks
1 parent d37cafd commit 6e84b74

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

service/history/api/isactivitytaskvalid/api.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ func isActivityTaskValid(
5757
}
5858

5959
ai, ok := mutableState.GetActivityInfo(scheduledEventID)
60-
if ok && ai.StartedEventId == common.EmptyEventID && ai.GetStamp() == stamp {
61-
return true, nil
60+
if !ok || ai.StartedEventId != common.EmptyEventID {
61+
return false, nil
6262
}
63-
return false, nil
63+
64+
if ai.GetStamp() > 0 && stamp > 0 && ai.GetStamp() != stamp {
65+
return false, nil
66+
}
67+
68+
return true, nil
6469
}

service/history/api/isactivitytaskvalid/api_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,32 @@ func (s *apiSuite) TestWorkflowRunning_ActivityTaskStarted() {
8989
func (s *apiSuite) TestWorkflowRunning_ActivityTaskStampMismatch() {
9090
s.mutableState.EXPECT().IsWorkflowExecutionRunning().Return(true)
9191
activityScheduleEventID := rand.Int63()
92+
const storedStamp = int32(456)
9293
s.mutableState.EXPECT().GetActivityInfo(activityScheduleEventID).Return(&persistencespb.ActivityInfo{
9394
ScheduledEventId: activityScheduleEventID,
9495
StartedEventId: common.EmptyEventID,
95-
Stamp: rand.Int31(),
96+
Stamp: storedStamp,
9697
}, true)
9798

98-
valid, err := isActivityTaskValid(s.workflowLease, activityScheduleEventID, rand.Int31())
99+
valid, err := isActivityTaskValid(s.workflowLease, activityScheduleEventID, storedStamp+1)
99100
s.NoError(err)
100101
s.False(valid)
101102
}
102103

104+
func (s *apiSuite) TestWorkflowRunning_ActivityTaskStampLegacy() {
105+
s.mutableState.EXPECT().IsWorkflowExecutionRunning().Return(true)
106+
activityScheduleEventID := rand.Int63()
107+
s.mutableState.EXPECT().GetActivityInfo(activityScheduleEventID).Return(&persistencespb.ActivityInfo{
108+
ScheduledEventId: activityScheduleEventID,
109+
StartedEventId: common.EmptyEventID,
110+
Stamp: 0,
111+
}, true)
112+
113+
valid, err := isActivityTaskValid(s.workflowLease, activityScheduleEventID, 0)
114+
s.NoError(err)
115+
s.True(valid)
116+
}
117+
103118
func (s *apiSuite) TestWorkflowRunning_ActivityTaskMissing() {
104119
s.mutableState.EXPECT().IsWorkflowExecutionRunning().Return(true)
105120
activityScheduleEventID := rand.Int63()

0 commit comments

Comments
 (0)