Skip to content

Commit

Permalink
Avoid mocking the value returned in global SETTINGS constant. (elasti…
Browse files Browse the repository at this point in the history
…c#16245)

This a refactoring of test fixture.
Avoid mocking the value returned in global SETTINGS constant. Use instead the local setting map instance used in subject creation.
  • Loading branch information
andsel committed Jul 12, 2024
1 parent 638b9e1 commit 313781b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions logstash-core/spec/logstash/java_pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,18 @@ def flush(options)
let(:dead_letter_queue_enabled) { false }
let(:dead_letter_queue_path) { }
let(:pipeline_settings_obj) { LogStash::SETTINGS.clone }
let(:pipeline_settings) { {} }
let(:pipeline_settings) do
{
"dead_letter_queue.enable" => dead_letter_queue_enabled,
"path.dead_letter_queue" => dead_letter_queue_path
}
end
let(:max_retry) {10} #times
let(:timeout) {120} #seconds

before :each do
pipeline_workers_setting = LogStash::SETTINGS.get_setting("pipeline.workers")
allow(pipeline_workers_setting).to receive(:default).and_return(worker_thread_count)
dlq_enabled_setting = LogStash::SETTINGS.get_setting("dead_letter_queue.enable")
allow(dlq_enabled_setting).to receive(:value).and_return(dead_letter_queue_enabled)
dlq_path_setting = LogStash::SETTINGS.get_setting("path.dead_letter_queue")
allow(dlq_path_setting).to receive(:value).and_return(dead_letter_queue_path)

pipeline_settings.each {|k, v| pipeline_settings_obj.set(k, v) }
end
Expand Down Expand Up @@ -297,7 +298,7 @@ def flush(options)
EOS
end
let(:dummyabortingoutput) { DummyAbortingOutput.new }
let(:pipeline_settings) { { "pipeline.batch.size" => 2, "queue.type" => "persisted"} }
let(:pipeline_settings) { super().merge({ "pipeline.batch.size" => 2, "queue.type" => "persisted"}) }

let(:collected_metric) { metric_store.get_with_path("stats/events") }
let (:queue_client_batch) { double("Acked queue client Mock") }
Expand Down Expand Up @@ -403,7 +404,7 @@ def flush(options)
end

context "a crashing worker using memory queue" do
let(:pipeline_settings) { { "pipeline.batch.size" => 1, "pipeline.workers" => 1, "queue.type" => "memory"} }
let(:pipeline_settings) { super().merge({ "pipeline.batch.size" => 1, "pipeline.workers" => 1, "queue.type" => "memory"}) }

it "does not raise in the main thread, terminates the run thread and finishes execution" do
# first make sure we keep the input plugin in the run method for now
Expand All @@ -430,7 +431,7 @@ def flush(options)
end

context "a crashing worker using persisted queue" do
let(:pipeline_settings) { { "pipeline.batch.size" => 1, "pipeline.workers" => 1, "queue.type" => "persisted"} }
let(:pipeline_settings) { super().merge({ "pipeline.batch.size" => 1, "pipeline.workers" => 1, "queue.type" => "persisted"}) }

it "does not raise in the main thread, terminates the run thread and finishes execution" do
# first make sure we keep the input plugin in the run method for now
Expand Down Expand Up @@ -522,7 +523,7 @@ def flush(options)
end

context "when there is command line -w N set" do
let(:pipeline_settings) { {"pipeline.workers" => override_thread_count } }
let(:pipeline_settings) { super().merge({"pipeline.workers" => override_thread_count }) }
it "starts multiple filter thread" do
msg = "Warning: Manual override - there are filters that might" +
" not work with multiple worker threads"
Expand Down Expand Up @@ -811,7 +812,7 @@ def flush(options)
describe "max inflight warning" do
let(:config) { "input { dummyinput {} } output { dummyoutput {} }" }
let(:batch_size) { 1 }
let(:pipeline_settings) { { "pipeline.batch.size" => batch_size, "pipeline.workers" => 1 } }
let(:pipeline_settings) { super().merge({ "pipeline.batch.size" => batch_size, "pipeline.workers" => 1 }) }
let(:pipeline) { mock_java_pipeline_from_string(config, pipeline_settings_obj) }
let(:logger) { pipeline.logger }
let(:warning_prefix) { Regexp.new("CAUTION: Recommended inflight events max exceeded!") }
Expand Down Expand Up @@ -1221,7 +1222,7 @@ def flush(options)

subject { mock_java_pipeline_from_string(config, pipeline_settings_obj, metric) }

let(:pipeline_settings) { { "pipeline.id" => pipeline_id } }
let(:pipeline_settings) { super().merge({ "pipeline.id" => pipeline_id }) }
let(:pipeline_id) { "main" }
let(:number_of_events) { 420 }
let(:dummy_id) { "my-multiline" }
Expand Down

0 comments on commit 313781b

Please sign in to comment.