move version conflict logging for mark as complete to sqlstore package

This commit is contained in:
bergquist
2018-10-02 14:23:18 +02:00
parent 9d3659d30d
commit 67e5f62514
3 changed files with 12 additions and 19 deletions
+4 -1
View File
@@ -259,7 +259,10 @@ func SetAlertNotificationStateToCompleteCommand(ctx context.Context, cmd *m.SetA
}
if current.Version != version {
return m.ErrAlertNotificationStateVersionConflict
sqlog.Error(
`notification state out of sync. the notification
is marked as complete but has been modified between
set as pending and completion.`, "notifierId", current.NotifierId)
}
return nil
@@ -77,19 +77,20 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
So(query3.Result.UpdatedAt, ShouldEqual, now.Unix())
})
Convey("Update existing state to completed should update database, but return version mismatch", func() {
Convey("Update existing state to completed should update database. regardless of version", func() {
s := *query.Result
unknownVersion := int64(1000)
cmd := models.SetAlertNotificationStateToCompleteCommand{
Id: s.Id,
Version: 1000,
Version: unknownVersion,
}
err := SetAlertNotificationStateToCompleteCommand(context.Background(), &cmd)
So(err, ShouldEqual, models.ErrAlertNotificationStateVersionConflict)
So(err, ShouldBeNil)
query3 := &models.GetOrCreateNotificationStateQuery{AlertId: alertID, OrgId: orgID, NotifierId: notifierID}
err = GetOrCreateAlertNotificationState(context.Background(), query3)
So(err, ShouldBeNil)
So(query3.Result.Version, ShouldEqual, 1001)
So(query3.Result.Version, ShouldEqual, unknownVersion+1)
So(query3.Result.State, ShouldEqual, models.AlertNotificationStateCompleted)
So(query3.Result.UpdatedAt, ShouldEqual, now.Unix())
})