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 6142e0c77c
commit 643568038f
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 # We need to create theses dummy classes to know how many
# events where actually generated by the pipeline and successfully send to the output. # 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. # 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!(:dummy_output2) { DummyOutput2.new }
let(:initial_generator_threshold) { 1000 } let(:initial_generator_threshold) { 1000 }
before :each do 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(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("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("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) allow(LogStash::Plugin).to receive(:lookup).with("output", "dummyoutput2").and_return(DummyOutput2)
@abort_on_exception = Thread.abort_on_exception @abort_on_exception = Thread.abort_on_exception
@ -435,7 +435,7 @@ describe LogStash::Agent do
end end
# wait for some events to reach the dummy_output # 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 end
after :each do after :each do
@ -461,7 +461,7 @@ describe LogStash::Agent do
subject.send(:"reload_pipeline!", "main") subject.send(:"reload_pipeline!", "main")
# wait until pipeline restarts # wait until pipeline restarts
sleep(0.01) until dummy_output2.events.size > 0 sleep(0.01) until dummy_output2.events_received > 0
end end
it "resets the pipeline metric collector" do it "resets the pipeline metric collector" do

View file

@ -48,4 +48,32 @@ module LogStash module Outputs
def close def close
end end
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 end end