Change the assertions in the config reloading spec

The assertions was using dummy outputs and kept received events into an
array in memory, but the test actually only needed to match the number
of events it received, this PR add a DroppingDummyOutput that wont
retain the events in memory.

The previous implementation was causing a OOM issue when running the
test on a very fast machine.

Fixes: #6335

Fixes #6346
This commit is contained in:
Pier-Hugues Pellerin 2016-12-02 12:33:42 -05:00
parent 5f0d784df4
commit 9bd6a2b6a9
2 changed files with 34 additions and 6 deletions

View file

@ -411,19 +411,19 @@ describe LogStash::Agent do
# We need to create theses dummy classes to know how many
# events where actually generated by the pipeline and successfully send to the output.
# Theses values are compared with what we store in the metric store.
class DummyOutput2 < LogStash::Outputs::DummyOutput; end
class DummyOutput2 < LogStash::Outputs::DroppingDummyOutput; end
let!(:dummy_output) { DummyOutput.new }
let!(:dummy_output) { LogStash::Outputs::DroppingDummyOutput.new }
let!(:dummy_output2) { DummyOutput2.new }
let(:initial_generator_threshold) { 1000 }
before :each do
allow(DummyOutput).to receive(:new).at_least(:once).with(anything).and_return(dummy_output)
allow(LogStash::Outputs::DroppingDummyOutput).to receive(:new).at_least(:once).with(anything).and_return(dummy_output)
allow(DummyOutput2).to receive(:new).at_least(:once).with(anything).and_return(dummy_output2)
allow(LogStash::Plugin).to receive(:lookup).with("input", "generator").and_return(LogStash::Inputs::Generator)
allow(LogStash::Plugin).to receive(:lookup).with("codec", "plain").and_return(LogStash::Codecs::Plain)
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(DummyOutput)
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput").and_return(LogStash::Outputs::DroppingDummyOutput)
allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput2").and_return(DummyOutput2)
@abort_on_exception = Thread.abort_on_exception
@ -435,7 +435,7 @@ describe LogStash::Agent do
end
# wait for some events to reach the dummy_output
sleep(0.01) until dummy_output.events.size > initial_generator_threshold
sleep(0.01) until dummy_output.events_received > initial_generator_threshold
end
after :each do
@ -461,7 +461,7 @@ describe LogStash::Agent do
subject.send(:"reload_pipeline!", "main")
# wait until pipeline restarts
sleep(0.01) until dummy_output2.events.size > 0
sleep(0.01) until dummy_output2.events_received > 0
end
it "resets the pipeline metric collector" do

View file

@ -48,4 +48,32 @@ module LogStash module Outputs
def close
end
end
class DroppingDummyOutput < LogStash::Outputs::Base
config_name "droppingdummyoutput"
milestone 2
attr_reader :num_closes
def initialize(params={})
super
@num_closes = 0
@events_received = Concurrent::AtomicFixnum.new(0)
end
def register
end
def receive(event)
@events_received.increment
end
def events_received
@events_received.value
end
def close
@num_closes = 1
end
end
end end