From f8b6bdc39b994ba2460818b4ef884080bc4cbccb Mon Sep 17 00:00:00 2001 From: Ry Biesemeyer Date: Mon, 21 Jun 2021 08:14:25 -0700 Subject: [PATCH] ispec: fix cross-spec leak from fatal error integration specs (#13002) Because the "Fatal Error" specs specifically inject fatal errors during execution, and do so by reacting to a "poison" event, the fatal error prevents the poison event from being ACK'd in the underlying queue. By specifying a one-off temporary data directory in these specs and cleaning up after ourselves, we ensure that a PQ containing un-ACK'd events isn't leaked to the next spec to run. (cherry picked from commit 6032e5ff642cfa9486c7c8e3245b051f32b22241) --- qa/integration/specs/fatal_error_spec.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/qa/integration/specs/fatal_error_spec.rb b/qa/integration/specs/fatal_error_spec.rb index 910f921a407..7acebd3299f 100644 --- a/qa/integration/specs/fatal_error_spec.rb +++ b/qa/integration/specs/fatal_error_spec.rb @@ -28,10 +28,19 @@ @logstash = @fixture.get_service("logstash") end - after(:each) { @logstash.teardown } + after(:each) do + @logstash.teardown + FileUtils.rm_rf(temp_dir) + end let(:timeout) { 90 } # seconds let(:temp_dir) { Stud::Temporary.directory("logstash-error-test") } + let(:logs_dir) { File.join(temp_dir, "logs") } + + # ensure PQ data is isolated. + # We crash before ACK-ing events, so we need to make sure we don't + # leave those un-ACK'd events in the queue to poison a subsequent test. + let(:data_dir) { File.join(temp_dir, "data") } it "halts LS on fatal error" do config = "input { generator { count => 1 message => 'a fatal error' } } " @@ -42,7 +51,7 @@ expect(@logstash.exit_code).to be 120 - log_file = "#{temp_dir}/logstash-plain.log" + log_file = "#{logs_dir}/logstash-plain.log" expect( File.exists?(log_file) ).to be true expect( File.read(log_file) ).to match /\[FATAL\]\[org.logstash.Logstash.*?java.lang.AssertionError: a fatal error/m end @@ -55,13 +64,16 @@ expect(@logstash.exit_code).to be 0 # normal exit - log_file = "#{temp_dir}/logstash-plain.log" + log_file = "#{logs_dir}/logstash-plain.log" expect( File.exists?(log_file) ).to be true expect( File.read(log_file) ).to match /\[ERROR\]\[org.logstash.Logstash.*?uncaught exception \(in thread .*?java.io.EOFException: unexpected/m end def spawn_logstash_and_wait_for_exit!(config, timeout) - @logstash.spawn_logstash('-w', '1', '--path.logs', temp_dir, '-e', config) + @logstash.spawn_logstash('--pipeline.workers=1', + '--path.logs', logs_dir, + '--path.data', data_dir, + '--config.string', config) time = Time.now while (Time.now - time) < timeout