tests: ls2ls delay checking until events have been processed (#17167) (#17252)

* tests: ls2ls delay checking until events have been processed

* Make sure upstream sends expected number of events before checking the expectation with downstream. Remove unnecessary or duplicated logics from the spec.

* Add exception handling in `wait_for_rest_api` to make wait for LS REST API retriable.

---------

Co-authored-by: Mashhur <mashhur.sattorov@elastic.co>
Co-authored-by: Mashhur <99575341+mashhurs@users.noreply.github.com>
(cherry picked from commit 73ffa243bf)

Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2025-03-05 12:17:55 -08:00 committed by GitHub
parent 556c451072
commit 36ae11cf65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 25 deletions

View file

@ -220,7 +220,9 @@ class LogstashService < Service
# check REST API is responsive
def rest_active?
result = monitoring_api.node_info
started = !result.nil?
!result.nil?
rescue
return false
end
def monitoring_api

View file

@ -27,12 +27,9 @@ describe "Logstash to Logstash communication Integration test" do
before(:all) {
@fixture = Fixture.new(__FILE__)
# backup original setting file since we change API port number, and restore after all tests
FileUtils.cp(@fixture.get_service('logstash').application_settings_file, "#{@fixture.get_service('logstash').application_settings_file}.original")
}
after(:all) {
FileUtils.mv("#{@fixture.get_service('logstash').application_settings_file}.original", @fixture.get_service('logstash').application_settings_file)
@fixture.teardown
}
@ -57,26 +54,10 @@ describe "Logstash to Logstash communication Integration test" do
"--path.config", config_to_temp_file(@fixture.config(config_name, options)),
"--path.data", get_temp_path_dir,
"--api.http.port", api_port.to_s)
wait_for_logstash(logstash_service)
logstash_service.wait_for_rest_api
yield logstash_service
ensure
logstash_service&.teardown
end
def wait_for_logstash(service)
wait_in_seconds = 60
while wait_in_seconds > 0 do
begin
return if service.rest_active?
rescue => e
puts "Exception: #{e.message}"
wait_in_seconds -= 1
sleep 1
end
end
raise "Logstash is not responsive after 60 seconds."
logstash_service.teardown
end
let(:num_retries) { 60 }
@ -97,8 +78,8 @@ describe "Logstash to Logstash communication Integration test" do
try(num_retries) do
downstream_event_stats = downstream_logstash_service.monitoring_api.event_stats
expect(downstream_event_stats).to include({"in" => num_events}), lambda { "expected #{num_events} events to have been received by downstream"}
expect(downstream_event_stats).to include({"in" => num_events}), lambda { "expected #{num_events} events to have been received by downstream" }
expect(downstream_event_stats).to include({"out" => num_events}), lambda { "expected #{num_events} events to have been processed by downstream" }
end
# make sure received events are in the file
@ -122,4 +103,4 @@ describe "Logstash to Logstash communication Integration test" do
include_examples "send events"
end
end
end