Пример #1
0
func startApi(done chan struct{}) string {
	log.NewLogger(0, "console", fmt.Sprintf(`{"level": %d, "formatting":true}`, 1))
	stats, err := helper.New(false, "localhost:8125", "standard", "task-server", "default")
	if err != nil {
		panic(fmt.Errorf("failed to initialize statsd. %s", err))
	}

	sqlstore.NewEngine("sqlite3", ":memory:", true)
	//sqlstore.NewEngine("sqlite3", "file:/tmp/task-server-test.db?cache=shared&mode=rwc&_loc=Local", true)

	addTestData()

	m := api.NewApi(adminKey, stats)

	// define our own listner so we can call Close on it
	l, err := net.Listen("tcp", "localhost:0")
	if err != nil {
		panic(err.Error())
	}

	go http.Serve(l, m)
	go func() {
		<-done
		l.Close()
	}()

	return fmt.Sprintf("http://%s/", l.Addr().String())
}
Пример #2
0
func BenchmarkHelperCesaro(b *testing.B) {
	s := newServer()
	c, err := helper.New(true, addr, "standard", prefix, "")
	if err != nil {
		b.Fatal(err)
	}
	counter := c.NewCount(counterKey)
	gauge := c.NewGauge(gaugeKey, 0)
	timing := c.NewTimer(timingKey, 0)
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		counter.Inc(1)
		gauge.Value(gaugeValue)
		timing.Value(tValDur)
	}
	b.StopTimer()
	s.Close()
}