Ejemplo n.º 1
0
// TestBehaviorEventBufferSize tests the setting of
// the event buffer size.
func TestBehaviorEventBufferSize(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)

	env := cells.NewEnvironment("event-buffer")
	defer env.Stop()

	err := env.StartCell("negative", newEventBufferBehavior(-8))
	assert.Nil(err)
	ci := cells.InspectCell(env, "negative")
	assert.Equal(ci.EventBufferSize(), cells.MinEventBufferSize)

	err = env.StartCell("low", newEventBufferBehavior(1))
	assert.Nil(err)
	ci = cells.InspectCell(env, "low")
	assert.Equal(ci.EventBufferSize(), cells.MinEventBufferSize)

	err = env.StartCell("high", newEventBufferBehavior(2*cells.MinEventBufferSize))
	assert.Nil(err)
	ci = cells.InspectCell(env, "high")
	assert.Equal(ci.EventBufferSize(), 2*cells.MinEventBufferSize)
}
Ejemplo n.º 2
0
// TestBehaviorEmitTimeout tests the setting of
// the emit timeout.
func TestBehaviorEmitTimeout(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)

	env := cells.NewEnvironment("emit-timeout")
	defer env.Stop()

	err := env.StartCell("low", newTestEmitTimeoutBehavior(time.Millisecond))
	assert.Nil(err)
	ci := cells.InspectCell(env, "low")
	assert.Equal(ci.EmitTimeout(), cells.MinEmitTimeout)

	err = env.StartCell("correct", newTestEmitTimeoutBehavior(10*time.Second))
	assert.Nil(err)
	ci = cells.InspectCell(env, "correct")
	assert.Equal(ci.EmitTimeout(), 10*time.Second)

	err = env.StartCell("high", newTestEmitTimeoutBehavior(2*cells.MaxEmitTimeout))
	assert.Nil(err)
	ci = cells.InspectCell(env, "high")
	assert.Equal(ci.EmitTimeout(), cells.MaxEmitTimeout)
}
Ejemplo n.º 3
0
// TestBehaviorEmitTimeoutSetting tests the setting of
// the emit timeout.
func TestBehaviorEmitTimeoutSetting(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	minSeconds := int(cells.MinEmitTimeout.Seconds() / 5)
	maxSeconds := int(cells.MaxEmitTimeout.Seconds() / 5)

	env := cells.NewEnvironment("emit-timeout-setting")
	defer env.Stop()

	err := env.StartCell("low", newEmitTimeoutBehavior(time.Millisecond))
	assert.Nil(err)
	ci := cells.InspectCell(env, "low")
	assert.Equal(ci.EmitTimeout(), minSeconds)

	err = env.StartCell("correct", newEmitTimeoutBehavior(10*time.Second))
	assert.Nil(err)
	ci = cells.InspectCell(env, "correct")
	assert.Equal(ci.EmitTimeout(), 2)

	err = env.StartCell("high", newEmitTimeoutBehavior(2*cells.MaxEmitTimeout))
	assert.Nil(err)
	ci = cells.InspectCell(env, "high")
	assert.Equal(ci.EmitTimeout(), maxSeconds)
}
Ejemplo n.º 4
0
// TestBehaviorRecoveringFrequency tests the setting of
// the recovering frequency.
func TestBehaviorRecoveringFrequency(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)

	env := cells.NewEnvironment("recovering-frequency")
	defer env.Stop()

	err := env.StartCell("negative", newRecoveringFrequencyBehavior(-1, time.Second))
	assert.Nil(err)
	ci := cells.InspectCell(env, "negative")
	assert.Equal(ci.RecoveringNumber(), cells.MinRecoveringNumber)
	assert.Equal(ci.RecoveringDuration(), cells.MinRecoveringDuration)

	err = env.StartCell("low", newRecoveringFrequencyBehavior(10, time.Millisecond))
	assert.Nil(err)
	ci = cells.InspectCell(env, "low")
	assert.Equal(ci.RecoveringNumber(), cells.MinRecoveringNumber)
	assert.Equal(ci.RecoveringDuration(), cells.MinRecoveringDuration)

	err = env.StartCell("high", newRecoveringFrequencyBehavior(12, time.Minute))
	assert.Nil(err)
	ci = cells.InspectCell(env, "high")
	assert.Equal(ci.RecoveringNumber(), 12)
	assert.Equal(ci.RecoveringDuration(), time.Minute)
}