Пример #1
0
// Test of the DSR monitor.
func TestDsrMonitor(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	// Register monitoring funcs.
	monitoring.Register("dsr:a", func() (string, error) { return "A", nil })
	monitoring.Register("dsr:b", func() (string, error) { return "4711", nil })
	monitoring.Register("dsr:c", func() (string, error) { return "2012-02-15", nil })
	monitoring.Register("dsr:d", func() (string, error) { a := 1; a = a / (a - a); return fmt.Sprintf("%d", a), nil })
	// Need some time to let that backend catch up queued registerings.
	time.Sleep(time.Millisecond)
	// Asserts.
	dsv, err := monitoring.ReadStatus("foo")
	assert.ErrorMatch(err, `\[MONITORING:.*\] dynamic status "foo" does not exist`, "reading non-existent status")
	dsv, err = monitoring.ReadStatus("dsr:b")
	assert.Nil(err, "no error expected")
	assert.Equal(dsv, "4711", "status value should be correct")
	dsv, err = monitoring.ReadStatus("dsr:d")
	assert.NotNil(err, "error should be returned")
	assert.ErrorMatch(err, `\[MONITORING:.*\] monitor backend panicked`, "error inside retrieval has to be catched")
}
Пример #2
0
// Test the behavior after an internal panic.
func TestInternalPanic(t *testing.T) {
	assert := asserts.NewTestingAssertion(t, true)
	// Register monitoring func with panic.
	monitoring.Register("panic", func() (string, error) { panic("ouch"); return "panic", nil })
	// Need some time to let that backend catch up queued registering.
	time.Sleep(time.Millisecond)
	// Asserts.
	dsv, err := monitoring.ReadStatus("panic")
	assert.Empty(dsv, "no dynamic status value")
	assert.ErrorMatch(err, `\[MONITORING:.*\] monitor backend panicked`, "monitor restarted due to panic")
}