Example #1
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)
}
Example #2
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() {})
	}
}
Example #3
0
// BenchmarkFilteredStandardBackendETM checks the performance of the ETM
// of the standard backend when filtered.
func BenchmarkFilteredStandardBackendETM(b *testing.B) {
	monitoring.SetBackend(monitoring.NewStandardBackend())
	monitoring.SetMeasuringsFilter(func(id string) bool {
		return id != "test"
	})
	defer monitoring.SetMeasuringsFilter(nil)

	for i := 0; i < b.N; i++ {
		monitoring.Measure("test", func() {})
	}
}