Exemplo n.º 1
0
// BenchmarkNullBackendETM checks the performance of the ETM of the
// null backend.
func BenchmarkNullBackendETM(b *testing.B) {
	monitoring.SetBackend(monitoring.NewNullBackend())

	for i := 0; i < b.N; i++ {
		monitoring.Measure("test", func() {})
	}
}
Exemplo n.º 2
0
// TestBackendSwitch tests the correct switching between backends.
func TestBackendSwitch(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	sleep := 10 * time.Millisecond
	// First standard.
	monitoring.SetBackend(monitoring.NewStandardBackend())
	monitoring.Measure("test-a", func() { time.Sleep(sleep) })
	time.Sleep(sleep)
	mp, err := monitoring.ReadMeasuringPoint("test-a")
	assert.Nil(err)
	assert.Equal(mp.Count(), int64(1))
	assert.True(sleep <= mp.AvgDuration() && mp.AvgDuration() <= 2*sleep)
	// Then null.
	monitoring.SetBackend(monitoring.NewNullBackend())
	monitoring.Measure("test", func() { time.Sleep(sleep) })
	mp, err = monitoring.ReadMeasuringPoint("test")
	assert.Nil(err)
	assert.Equal(mp.ID(), "null")
	assert.Equal(mp.Count(), int64(0))
	// Finally standard again.
	monitoring.SetBackend(monitoring.NewStandardBackend())
	monitoring.Measure("test-b", func() { time.Sleep(sleep) })
	time.Sleep(sleep)
	mp, err = monitoring.ReadMeasuringPoint("test-a")
	assert.ErrorMatch(err, `.* measuring point "test-a" does not exist`)
	mp, err = monitoring.ReadMeasuringPoint("test-b")
	assert.Nil(err)
	assert.Equal(mp.Count(), int64(1))
	assert.True(sleep <= mp.AvgDuration() && mp.AvgDuration() <= 2*sleep)
}
Exemplo n.º 3
0
// BenchmarkSmpleEmitNullMonitoring is a simple emitting to one cell
// with the null monitor.
func BenchmarkSmpleEmitNullMonitoring(b *testing.B) {
	monitoring.SetBackend(monitoring.NewNullBackend())
	env := cells.NewEnvironment("simple-emit-null")
	defer env.Stop()

	env.StartCell("null", &nullBehavior{})

	event, _ := cells.NewEvent("foo", "bar", nil)

	for i := 0; i < b.N; i++ {
		env.Emit("null", event)
	}
}