diff --git a/qa/docker/shared_examples/container_options.rb b/qa/docker/shared_examples/container_options.rb index 48c51d382..dce1e8486 100644 --- a/qa/docker/shared_examples/container_options.rb +++ b/qa/docker/shared_examples/container_options.rb @@ -88,8 +88,7 @@ shared_examples_for 'it applies settings correctly' do |flavor| expect(output_plugins[0].dig('name')).to eql('elasticsearch') # check if logs contain the ES request with the resolved ${USER} - container_logs = @container.logs(stdout: true) - expect(container_logs.include?('https://kimchy:xxxxxx@es:9200')).to be true + wait_for_log_message(@container, 'https://kimchy:xxxxxx@es:9200') end end end diff --git a/qa/docker/shared_examples/xpack.rb b/qa/docker/shared_examples/xpack.rb index 254e0354c..5b954b25f 100644 --- a/qa/docker/shared_examples/xpack.rb +++ b/qa/docker/shared_examples/xpack.rb @@ -48,14 +48,11 @@ shared_examples_for 'a container with xpack features' do |flavor| expect(settings['xpack.management.pipeline.id']).to eq("${XPACK_MANAGEMENT_PIPELINE_ID}") expect(settings['xpack.management.elasticsearch.hosts']).to eq("${XPACK_MANAGEMENT_ELASTICSEARCH_HOSTS}") - # get container logs - container_logs = container.logs(stdout: true) - # check if logs contain node3 & node4 values actually resolved and used - expect(container_logs.include?('pipeline_id=>["*"]')).to be true + wait_for_log_message(container, 'pipeline_id=>["*"]', :stdout) # note that, we are not spinning up ES nodes, so values can be in errors or in pool update logs - expect(container_logs.include?('http://node3:9200')).to be true - expect(container_logs.include?('http://node4:9200')).to be true + wait_for_log_message(container, 'http://node3:9200', :stdout) + wait_for_log_message(container, 'http://node4:9200', :stdout) end end end diff --git a/qa/docker/spec/spec_helper.rb b/qa/docker/spec/spec_helper.rb index f79514d5a..eb6622dc7 100644 --- a/qa/docker/spec/spec_helper.rb +++ b/qa/docker/spec/spec_helper.rb @@ -49,6 +49,13 @@ def wait_for_pipeline(container, pipeline = 'main') end end +def wait_for_log_message(container, search_string, stream = :stdout) + Stud.try(40.times, [NoMethodError, Docker::Error::ConflictError, RSpec::Expectations::ExpectationNotMetError, TypeError]) do + container_logs = container.logs(stream => true) + expect(container_logs.include?(search_string)).to be true + end +end + def cleanup_container(container) unless container.nil? begin