Skip to content

Commit ab11d4e

Browse files
mergify[bot]yaauie
andauthored
tests: ls2ls delay checking until events have been processed (#17167) (#17250)
* 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 <[email protected]> Co-authored-by: Mashhur <[email protected]> (cherry picked from commit 73ffa24) Co-authored-by: Ry Biesemeyer <[email protected]>
1 parent 1a190a4 commit ab11d4e

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

qa/integration/services/logstash_service.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ def is_port_open?
219219
# check REST API is responsive
220220
def rest_active?
221221
result = monitoring_api.node_info
222-
started = !result.nil?
222+
!result.nil?
223+
rescue
224+
return false
223225
end
224226

225227
def monitoring_api

qa/integration/specs/logstash_to_logstash_spec.rb

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727

2828
before(:all) {
2929
@fixture = Fixture.new(__FILE__)
30-
# backup original setting file since we change API port number, and restore after all tests
31-
FileUtils.cp(@fixture.get_service('logstash').application_settings_file, "#{@fixture.get_service('logstash').application_settings_file}.original")
3230
}
3331

3432
after(:all) {
35-
FileUtils.mv("#{@fixture.get_service('logstash').application_settings_file}.original", @fixture.get_service('logstash').application_settings_file)
3633
@fixture.teardown
3734
}
3835

@@ -57,26 +54,10 @@ def run_logstash_instance(config_name, options = {}, &block)
5754
"--path.config", config_to_temp_file(@fixture.config(config_name, options)),
5855
"--path.data", get_temp_path_dir,
5956
"--api.http.port", api_port.to_s)
60-
wait_for_logstash(logstash_service)
61-
57+
logstash_service.wait_for_rest_api
6258
yield logstash_service
63-
6459
ensure
65-
logstash_service&.teardown
66-
end
67-
68-
def wait_for_logstash(service)
69-
wait_in_seconds = 60
70-
while wait_in_seconds > 0 do
71-
begin
72-
return if service.rest_active?
73-
rescue => e
74-
puts "Exception: #{e.message}"
75-
wait_in_seconds -= 1
76-
sleep 1
77-
end
78-
end
79-
raise "Logstash is not responsive after 60 seconds."
60+
logstash_service.teardown
8061
end
8162

8263
let(:num_retries) { 60 }
@@ -97,8 +78,8 @@ def wait_for_logstash(service)
9778

9879
try(num_retries) do
9980
downstream_event_stats = downstream_logstash_service.monitoring_api.event_stats
100-
101-
expect(downstream_event_stats).to include({"in" => num_events}), lambda { "expected #{num_events} events to have been received by downstream"}
81+
expect(downstream_event_stats).to include({"in" => num_events}), lambda { "expected #{num_events} events to have been received by downstream" }
82+
expect(downstream_event_stats).to include({"out" => num_events}), lambda { "expected #{num_events} events to have been processed by downstream" }
10283
end
10384

10485
# make sure received events are in the file
@@ -122,4 +103,4 @@ def wait_for_logstash(service)
122103
include_examples "send events"
123104
end
124105

125-
end
106+
end

0 commit comments

Comments
 (0)