tech(alerting): fixes broken unit-tests

This commit is contained in:
bergquist
2016-05-23 14:51:41 +02:00
parent 9d500df2bb
commit 77ec575b46
3 changed files with 21 additions and 7 deletions
+9 -3
View File
@@ -30,10 +30,16 @@ type AlertRule struct {
Updated time.Time `json:"updated"`
}
type HeartBeat struct {
type AlertingClusterInfo struct {
ServerId string
ClusterSize int
UptimePosition int
}
type HeartBeatCommand struct {
ServerId string
Updated time.Time
Created time.Time
Result AlertingClusterInfo
}
type AlertRuleChange struct {
+10 -2
View File
@@ -5,6 +5,7 @@ import (
"strconv"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
@@ -47,9 +48,16 @@ func (this *Scheduler) heartBeat() {
//write heartBeat to db.
//get the modulus position of active servers
cmd := &m.HeartBeatCommand{ServerId: this.serverId}
log.Info("Heartbeat: Sending heartbeat from " + this.serverId)
this.clusterSize = 1
this.serverPosition = 1
err := bus.Dispatch(cmd)
if err != nil {
log.Error(1, "Failed to send heartbeat.")
} else {
this.clusterSize = cmd.Result.ClusterSize
this.serverPosition = cmd.Result.UptimePosition
}
}
func (this *Scheduler) Dispatch(reader RuleReader) {
+2 -2
View File
@@ -43,7 +43,7 @@ func TestAlertingScheduler(t *testing.T) {
scheduler.updateJobs(mockFn)
So(len(scheduler.jobs), ShouldEqual, 3)
So(scheduler.jobs[0].id, ShouldEqual, 1)
So(scheduler.jobs[0].rule.Id, ShouldEqual, 1)
})
Convey("six servers", func() {
@@ -57,7 +57,7 @@ func TestAlertingScheduler(t *testing.T) {
scheduler.updateJobs(mockFn)
So(len(scheduler.jobs), ShouldEqual, 1)
So(scheduler.jobs[0].id, ShouldEqual, 6)
So(scheduler.jobs[0].rule.Id, ShouldEqual, 6)
})
Convey("more servers then alerts", func() {