Skip to content

Commit

Permalink
hotfix(api) increase sleep and attempts count for lock (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
kissken authored Feb 1, 2024
1 parent a01185d commit 5a64957
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/controller/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/moira-alert/moira/support"
)

const maxTriggerLockAttempts = 10
const maxTriggerLockAttempts = 15

// UpdateTrigger update trigger data and trigger metrics in last state
func UpdateTrigger(dataBase moira.Database, trigger *dto.TriggerModel, triggerID string, timeSeriesNames map[string]bool) (*dto.SaveTriggerResponse, *api.ErrorResponse) {
Expand Down
28 changes: 14 additions & 14 deletions api/controller/trigger_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDeleteTriggerMetric(t *testing.T) {
Convey("Success delete from last check", t, func() {
expectedLastCheck := lastCheck
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(expectedLastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand All @@ -49,7 +49,7 @@ func TestDeleteTriggerMetric(t *testing.T) {
Convey("Success delete nothing to delete", t, func() {
expectedLastCheck := emptyLastCheck
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(expectedLastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand All @@ -67,7 +67,7 @@ func TestDeleteTriggerMetric(t *testing.T) {

Convey("No last check", t, func() {
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
err := DeleteTriggerMetric(dataBase, "super.metric1", triggerID)
Expand All @@ -84,15 +84,15 @@ func TestDeleteTriggerMetric(t *testing.T) {
Convey("AcquireTriggerCheckLock error", t, func() {
expected := fmt.Errorf("acquire error")
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(expected)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(expected)
err := DeleteTriggerMetric(dataBase, "super.metric1", triggerID)
So(err, ShouldResemble, api.ErrorInternalServer(expected))
})

Convey("GetTriggerLastCheck error", t, func() {
expected := fmt.Errorf("last check error")
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, expected)
err := DeleteTriggerMetric(dataBase, "super.metric1", triggerID)
Expand All @@ -102,7 +102,7 @@ func TestDeleteTriggerMetric(t *testing.T) {
Convey("RemovePatternsMetrics error", t, func() {
expected := fmt.Errorf("removePatternsMetrics err")
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(lastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(expected)
Expand All @@ -113,7 +113,7 @@ func TestDeleteTriggerMetric(t *testing.T) {
Convey("SetTriggerLastCheck error", t, func() {
expected := fmt.Errorf("removePatternsMetrics err")
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(lastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand Down Expand Up @@ -171,7 +171,7 @@ func TestDeleteTriggerNodataMetrics(t *testing.T) {
Convey("Success delete from last check, one NODATA", t, func() {
expectedLastCheck := lastCheckSingleNodata
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(expectedLastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand All @@ -184,7 +184,7 @@ func TestDeleteTriggerNodataMetrics(t *testing.T) {
Convey("Success delete from last check, many NODATA", t, func() {
expectedLastCheck := lastCheckWithNodataOnly
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(expectedLastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand All @@ -197,7 +197,7 @@ func TestDeleteTriggerNodataMetrics(t *testing.T) {
Convey("Success delete from last check, many NODATA + other statuses", t, func() {
expectedLastCheck := lastCheckWithManyStates
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(expectedLastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand All @@ -210,7 +210,7 @@ func TestDeleteTriggerNodataMetrics(t *testing.T) {
Convey("Success delete nothing to delete", t, func() {
expectedLastCheck := emptyLastCheck
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(expectedLastCheck, nil)
dataBase.EXPECT().RemovePatternsMetrics(trigger.Patterns).Return(nil)
Expand All @@ -228,7 +228,7 @@ func TestDeleteTriggerNodataMetrics(t *testing.T) {

Convey("No last check", t, func() {
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
err := DeleteTriggerNodataMetrics(dataBase, triggerID)
Expand All @@ -245,15 +245,15 @@ func TestDeleteTriggerNodataMetrics(t *testing.T) {
Convey("AcquireTriggerCheckLock error", t, func() {
expected := fmt.Errorf("acquire error")
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(expected)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(expected)
err := DeleteTriggerMetric(dataBase, "super.metric1", triggerID)
So(err, ShouldResemble, api.ErrorInternalServer(expected))
})

Convey("GetTriggerLastCheck error", t, func() {
expected := fmt.Errorf("last check error")
dataBase.EXPECT().GetTrigger(triggerID).Return(trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(nil)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(nil)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, expected)
err := DeleteTriggerNodataMetrics(dataBase, triggerID)
Expand Down
34 changes: 17 additions & 17 deletions api/controller/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestUpdateTrigger(t *testing.T) {
triggerModel := dto.TriggerModel{ID: uuid.Must(uuid.NewV4()).String()}
trigger := triggerModel.ToMoiraTrigger()
dataBase.EXPECT().GetTrigger(triggerModel.ID).Return(*trigger, nil)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 10)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 15)
dataBase.EXPECT().DeleteTriggerCheckLock(gomock.Any())
dataBase.EXPECT().GetTriggerLastCheck(gomock.Any()).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(gomock.Any(), gomock.Any(), trigger.TriggerSource).Return(nil)
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestSaveTrigger(t *testing.T) {

Convey("No timeSeries", t, func() {
Convey("No last check", func() {
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, gomock.Any(), trigger.TriggerSource).Return(nil)
Expand All @@ -85,7 +85,7 @@ func TestSaveTrigger(t *testing.T) {
})
Convey("Has last check", func() {
actualLastCheck := lastCheck
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(actualLastCheck, nil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, &emptyLastCheck, trigger.TriggerSource).Return(nil)
Expand All @@ -98,7 +98,7 @@ func TestSaveTrigger(t *testing.T) {

Convey("Has timeSeries", t, func() {
actualLastCheck := lastCheck
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, gomock.Any(), trigger.TriggerSource).Return(nil)
Expand All @@ -112,15 +112,15 @@ func TestSaveTrigger(t *testing.T) {
Convey("Errors", t, func() {
Convey("AcquireTriggerCheckLock error", func() {
expected := fmt.Errorf("acquireTriggerCheckLock error")
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10).Return(expected)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15).Return(expected)
resp, err := saveTrigger(dataBase, &trigger, triggerID, make(map[string]bool))
So(err, ShouldResemble, api.ErrorInternalServer(expected))
So(resp, ShouldBeNil)
})

Convey("GetTriggerLastCheck error", func() {
expected := fmt.Errorf("getTriggerLastCheck error")
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, expected)
resp, err := saveTrigger(dataBase, &trigger, triggerID, make(map[string]bool))
Expand All @@ -130,7 +130,7 @@ func TestSaveTrigger(t *testing.T) {

Convey("SetTriggerLastCheck error", func() {
expected := fmt.Errorf("setTriggerLastCheck error")
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, gomock.Any(), trigger.TriggerSource).Return(expected)
Expand All @@ -141,7 +141,7 @@ func TestSaveTrigger(t *testing.T) {

Convey("saveTrigger error", func() {
expected := fmt.Errorf("saveTrigger error")
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, gomock.Any(), trigger.TriggerSource).Return(nil)
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestVariousTtlState(t *testing.T) {
lastCheck.State = moira.StateNODATA
lastCheck.Score = 1000

dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, &lastCheck, trigger.TriggerSource).Return(nil)
Expand All @@ -187,7 +187,7 @@ func TestVariousTtlState(t *testing.T) {
lastCheck.State = moira.StateERROR
lastCheck.Score = 100

dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, &lastCheck, trigger.TriggerSource).Return(nil)
Expand All @@ -202,7 +202,7 @@ func TestVariousTtlState(t *testing.T) {
lastCheck.State = moira.StateWARN
lastCheck.Score = 1

dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, &lastCheck, trigger.TriggerSource).Return(nil)
Expand All @@ -217,7 +217,7 @@ func TestVariousTtlState(t *testing.T) {
lastCheck.State = moira.StateOK
lastCheck.Score = 0

dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, &lastCheck, trigger.TriggerSource).Return(nil)
Expand All @@ -232,7 +232,7 @@ func TestVariousTtlState(t *testing.T) {
lastCheck.State = moira.StateOK
lastCheck.Score = 0

dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().DeleteTriggerCheckLock(triggerID)
dataBase.EXPECT().GetTriggerLastCheck(triggerID).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(triggerID, &lastCheck, trigger.TriggerSource).Return(nil)
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestSetTriggerMaintenance(t *testing.T) {
var maintenanceTS int64 = 12347

Convey("Success setting metrics maintenance only", t, func() {
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().ReleaseTriggerCheckLock(triggerID)
dataBase.EXPECT().SetTriggerCheckMaintenance(triggerID, triggerMaintenance.Metrics, triggerMaintenance.Trigger, "", int64(0)).Return(nil)
err := SetTriggerMaintenance(dataBase, triggerID, triggerMaintenance, "", 0)
Expand All @@ -466,7 +466,7 @@ func TestSetTriggerMaintenance(t *testing.T) {
Convey("Success setting trigger maintenance only", t, func() {
triggerMaintenance.Trigger = &maintenanceTS
triggerMaintenance.Metrics = dto.MetricsMaintenance{}
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().ReleaseTriggerCheckLock(triggerID)
dataBase.EXPECT().SetTriggerCheckMaintenance(triggerID, triggerMaintenance.Metrics, triggerMaintenance.Trigger, "", int64(0)).Return(nil)
err := SetTriggerMaintenance(dataBase, triggerID, triggerMaintenance, "", 0)
Expand All @@ -476,7 +476,7 @@ func TestSetTriggerMaintenance(t *testing.T) {
Convey("Success setting metrics and trigger maintenance at once", t, func() {
triggerMaintenance.Trigger = &maintenanceTS
triggerMaintenance.Metrics = metricsMaintenance
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().ReleaseTriggerCheckLock(triggerID)
dataBase.EXPECT().SetTriggerCheckMaintenance(triggerID, triggerMaintenance.Metrics, triggerMaintenance.Trigger, "", int64(0)).Return(nil)
err := SetTriggerMaintenance(dataBase, triggerID, triggerMaintenance, "", 0)
Expand All @@ -485,7 +485,7 @@ func TestSetTriggerMaintenance(t *testing.T) {

Convey("Error", t, func() {
expected := fmt.Errorf("oooops! Error set")
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 10)
dataBase.EXPECT().AcquireTriggerCheckLock(triggerID, 15)
dataBase.EXPECT().ReleaseTriggerCheckLock(triggerID)
dataBase.EXPECT().SetTriggerCheckMaintenance(triggerID, triggerMaintenance.Metrics, triggerMaintenance.Trigger, "", int64(0)).Return(expected)
err := SetTriggerMaintenance(dataBase, triggerID, triggerMaintenance, "", 0)
Expand Down
8 changes: 4 additions & 4 deletions api/controller/triggers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestCreateTrigger(t *testing.T) {

Convey("Success with trigger.ID empty", t, func() {
triggerModel := dto.TriggerModel{}
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 10)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 15)
dataBase.EXPECT().DeleteTriggerCheckLock(gomock.Any())
dataBase.EXPECT().GetTriggerLastCheck(gomock.Any()).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
Expand All @@ -36,7 +36,7 @@ func TestCreateTrigger(t *testing.T) {
triggerID := uuid.Must(uuid.NewV4()).String()
triggerModel := dto.TriggerModel{ID: triggerID}
dataBase.EXPECT().GetTrigger(triggerModel.ID).Return(moira.Trigger{}, database.ErrNil)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 10)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 15)
dataBase.EXPECT().DeleteTriggerCheckLock(gomock.Any())
dataBase.EXPECT().GetTriggerLastCheck(gomock.Any()).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
Expand All @@ -51,7 +51,7 @@ func TestCreateTrigger(t *testing.T) {
triggerID := "Valid.Custom_Trigger~Name-42"
triggerModel := dto.TriggerModel{ID: triggerID}
dataBase.EXPECT().GetTrigger(triggerModel.ID).Return(moira.Trigger{}, database.ErrNil)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 10)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 15)
dataBase.EXPECT().DeleteTriggerCheckLock(gomock.Any())
dataBase.EXPECT().GetTriggerLastCheck(gomock.Any()).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestCreateTrigger(t *testing.T) {
triggerModel := dto.TriggerModel{ID: uuid.Must(uuid.NewV4()).String()}
expected := fmt.Errorf("soo bad trigger")
dataBase.EXPECT().GetTrigger(triggerModel.ID).Return(moira.Trigger{}, database.ErrNil)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 10)
dataBase.EXPECT().AcquireTriggerCheckLock(gomock.Any(), 15)
dataBase.EXPECT().DeleteTriggerCheckLock(gomock.Any())
dataBase.EXPECT().GetTriggerLastCheck(gomock.Any()).Return(moira.CheckData{}, database.ErrNil)
dataBase.EXPECT().SetTriggerLastCheck(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
Expand Down
2 changes: 1 addition & 1 deletion database/redis/triggers_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (connector *DbConnector) AcquireTriggerCheckLock(triggerID string, maxAttem
attemptsCount := 0
for !acquired && attemptsCount < maxAttemptsCount {
attemptsCount++
<-time.After(time.Millisecond * 500) //nolint
<-time.After(time.Second) //nolint
acquired, err = connector.SetTriggerCheckLock(triggerID)
if err != nil {
return err
Expand Down

0 comments on commit 5a64957

Please sign in to comment.