test(alerting): fixes broken unittests

pull/5622/head
bergquist 9 years ago
parent ef35184a80
commit 0c69c5afb1
  1. 7
      pkg/models/alerts.go
  2. 4
      pkg/services/alerting/scheduler.go
  3. 8
      pkg/services/sqlstore/alert_rule_test.go

@ -31,18 +31,19 @@ func (alertRule *AlertRuleDAO) ValidToSave() bool {
func (this *AlertRuleDAO) ContainsUpdates(other *AlertRuleDAO) bool {
result := false
result = result || this.Name != other.Name
result = result || this.Description != other.Description
json1, err1 := this.Expression.MarshalJSON()
json2, err2 := other.Expression.MarshalJSON()
if this.Expression != nil && other.Expression != nil {
json1, err1 := this.Expression.Encode()
json2, err2 := other.Expression.Encode()
if err1 != nil || err2 != nil {
return false
}
result = result || string(json1) != string(json2)
}
//don't compare .State! That would be insane.

@ -40,7 +40,7 @@ func (s *SchedulerImpl) Update(rules []*AlertRule) {
jobs[rule.Id] = job
}
s.log.Debug("Scheduler: Selected %d jobs", len(jobs))
s.log.Debug("Scheduler: Selected new jobs", "job count", len(jobs))
s.jobs = jobs
}
@ -49,7 +49,7 @@ func (s *SchedulerImpl) Tick(tickTime time.Time, execQueue chan *AlertJob) {
for _, job := range s.jobs {
if now%job.Rule.Frequency == 0 && job.Running == false {
log.Trace("Scheduler: Putting job on to exec queue: %s", job.Rule.Name)
s.log.Debug("Scheduler: Putting job on to exec queue", "name", job.Rule.Name)
execQueue <- job
}
}

@ -3,6 +3,7 @@ package sqlstore
import (
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models"
. "github.com/smartystreets/goconvey/convey"
)
@ -20,6 +21,7 @@ func TestAlertingDataAccess(t *testing.T) {
OrgId: testDash.OrgId,
Name: "Alerting title",
Description: "Alerting description",
Expression: simplejson.New(),
},
}
@ -54,8 +56,7 @@ func TestAlertingDataAccess(t *testing.T) {
Convey("Alerts with same dashboard id and panel id should update", func() {
modifiedItems := items
modifiedItems[0].Name = "New name"
//modifiedItems[0].State = "ALERT"
modifiedItems[0].Name = "Name"
modifiedCmd := m.SaveAlertsCommand{
DashboardId: testDash.Id,
@ -101,18 +102,21 @@ func TestAlertingDataAccess(t *testing.T) {
PanelId: 1,
Name: "1",
OrgId: 1,
Expression: simplejson.New(),
},
{
DashboardId: testDash.Id,
PanelId: 2,
Name: "2",
OrgId: 1,
Expression: simplejson.New(),
},
{
DashboardId: testDash.Id,
PanelId: 3,
Name: "3",
OrgId: 1,
Expression: simplejson.New(),
},
}

Loading…
Cancel
Save