func TestExecutor(t *testing.T) {
	listener := make(chan *graphite.Request, 100)
	setting.Rabbitmq = setting.RabbitmqSettings{
		Enabled: false,
	}
	Convey("executor must do the right thing", t, func() {

		fakeGraphiteReturner := func(org_id int64) (graphite.Context, error) {
			return fakeGraphite{
				resp: graphite.Response(
					make([]graphite.Series, 0),
				),
				queries: listener,
			}, nil
		}
		jobAt := func(ts int64) *m.AlertingJob {
			return &m.AlertingJob{
				Definition: m.CheckDef{
					CritExpr: `graphite("foo", "2m", "", "")`,
					WarnExpr: "0",
				},
				LastPointTs: time.Unix(ts, 0),
				GeneratedAt: time.Now(),
			}
		}
		jobQueue := make(chan *m.AlertingJob, 10)
		InitJobQueue(jobQueue)
		cache, err := lru.New(1000)
		if err != nil {
			panic(fmt.Sprintf("Can't create LRU: %s", err.Error()))
		}
		go ChanExecutor(fakeGraphiteReturner, jobQueue, cache)
		PublishJob(jobAt(0))
		PublishJob(jobAt(1))
		PublishJob(jobAt(2))
		PublishJob(jobAt(2))
		PublishJob(jobAt(1))
		PublishJob(jobAt(0))
		time.Sleep(100 * time.Millisecond) // yes hacky, can be synchronized later
		assertReq(t, listener, "expected the first job")
		assertReq(t, listener, "expected the second job")
		assertReq(t, listener, "expected the third job")
		assertEmpty(t, listener, "expected to be done after three jobs, with duplicates and old jobs ignored")
	})
}
func NewFakeGraphite(values [][]int, initialTs int64, step int) *fakeGraphite {
	fg := &fakeGraphite{}
	series := make([]graphite.Series, 0)
	for serieNum, pointSlice := range values {
		serie := graphite.Series{
			Target: fmt.Sprintf("test.serie.%d", serieNum),
		}
		for i, point := range pointSlice {
			v := json.Number(fmt.Sprintf("%d", point))
			ts := json.Number(fmt.Sprintf("%d", int(initialTs)+i*step))
			pt := graphite.DataPoint{}
			pt = append(pt, v, ts)
			serie.Datapoints = append(serie.Datapoints, pt)
		}
		series = append(series, serie)
	}

	fg.resp = graphite.Response(series)
	return fg
}