Skip to content

Commit

Permalink
Auto-reset: do not trigger/process reset task when reset point has e… (
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored May 6, 2019
1 parent 1608cf9 commit 3298cbf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
5 changes: 5 additions & 0 deletions service/history/workflowResetor.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,14 @@ func FindAutoResetPoint(badBinaries *workflow.BadBinaries, autoResetPoints *work
if badBinaries == nil || badBinaries.Binaries == nil || autoResetPoints == nil || autoResetPoints.Points == nil {
return
}
nowNano := time.Now().UnixNano()
for _, p := range autoResetPoints.Points {
bin, ok := badBinaries.Binaries[p.GetBinaryChecksum()]
if ok && p.GetResettable() {
if p.GetExpiringTimeNano() > 0 && nowNano > p.GetExpiringTimeNano() {
// reset point has expired and we may already deleted the history
continue
}
return bin.GetReason(), p
}
}
Expand Down
59 changes: 50 additions & 9 deletions service/history/workflowResetor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4132,11 +4132,11 @@ func (s *resetorSuite) TestApplyReset() {
}

func TestFindAutoResetPoint(t *testing.T) {
// case 1
// case 1: nil
_, pt := FindAutoResetPoint(nil, nil)
assert.Nil(t, pt)

// case 2
// case 2: empty
_, pt = FindAutoResetPoint(&workflow.BadBinaries{}, &workflow.ResetPoints{})
assert.Nil(t, pt)

Expand All @@ -4153,7 +4153,21 @@ func TestFindAutoResetPoint(t *testing.T) {
Resettable: common.BoolPtr(false),
}

// case 3
expiredNowNano := time.Now().UnixNano() - int64(time.Hour)
notExpiredNowNano := time.Now().UnixNano() + int64(time.Hour)
pt4 := &workflow.ResetPointInfo{
BinaryChecksum: common.StringPtr("expired"),
Resettable: common.BoolPtr(true),
ExpiringTimeNano: common.Int64Ptr(expiredNowNano),
}

pt5 := &workflow.ResetPointInfo{
BinaryChecksum: common.StringPtr("notExpired"),
Resettable: common.BoolPtr(true),
ExpiringTimeNano: common.Int64Ptr(notExpiredNowNano),
}

// case 3: two intersection
_, pt = FindAutoResetPoint(&workflow.BadBinaries{
Binaries: map[string]*workflow.BadBinaryInfo{
"abc": {},
Expand All @@ -4166,20 +4180,21 @@ func TestFindAutoResetPoint(t *testing.T) {
})
assert.Equal(t, pt.String(), pt0.String())

// case 4
// case 4: one intersection
_, pt = FindAutoResetPoint(&workflow.BadBinaries{
Binaries: map[string]*workflow.BadBinaryInfo{
"none": {},
"def": {},
"none": {},
"def": {},
"expired": {},
},
}, &workflow.ResetPoints{
Points: []*workflow.ResetPointInfo{
pt0, pt1, pt3,
pt4, pt0, pt1, pt3,
},
})
assert.Equal(t, pt.String(), pt1.String())

// case 4
// case 4: no intersection
_, pt = FindAutoResetPoint(&workflow.BadBinaries{
Binaries: map[string]*workflow.BadBinaryInfo{
"none1": {},
Expand All @@ -4192,7 +4207,7 @@ func TestFindAutoResetPoint(t *testing.T) {
})
assert.Nil(t, pt)

// case 5
// case 5: not resettable
_, pt = FindAutoResetPoint(&workflow.BadBinaries{
Binaries: map[string]*workflow.BadBinaryInfo{
"none1": {},
Expand All @@ -4204,4 +4219,30 @@ func TestFindAutoResetPoint(t *testing.T) {
},
})
assert.Nil(t, pt)

// case 6: one intersection of expired
_, pt = FindAutoResetPoint(&workflow.BadBinaries{
Binaries: map[string]*workflow.BadBinaryInfo{
"none": {},
"expired": {},
},
}, &workflow.ResetPoints{
Points: []*workflow.ResetPointInfo{
pt0, pt1, pt3, pt4, pt5,
},
})
assert.Nil(t, pt)

// case 7: one intersection of not expred
_, pt = FindAutoResetPoint(&workflow.BadBinaries{
Binaries: map[string]*workflow.BadBinaryInfo{
"none": {},
"notExpired": {},
},
}, &workflow.ResetPoints{
Points: []*workflow.ResetPointInfo{
pt0, pt1, pt3, pt4, pt5,
},
})
assert.Equal(t, pt.String(), pt5.String())
}

0 comments on commit 3298cbf

Please sign in to comment.