Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve read timeout failing #9888

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions testsuite/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
$current_password = 'admin'
$chromium_dev_tools = ENV.fetch('REMOTE_DEBUG', false)
$chromium_dev_port = 9222 + ENV['TEST_ENV_NUMBER'].to_i
# add_context('timeout_failure_counter', 0)
$timeout_failure_counter = 0
$timeout_threshold = 10 # Set the threshold for stopping the suite

# maximal wait before giving up
# the tests return much before that delay in case of success
Expand Down Expand Up @@ -130,23 +133,34 @@ def capybara_register_driver
# Define the current feature scope
Before do |scenario|
$feature_scope = scenario.location.file.split(%r{(\.feature|/)})[-2]
check_read_timeout_threshold
end

# Embed a screenshot after each failed scenario
# After hook to handle scenario failures and dump feature code coverage into Redis DB
After do |scenario|
check_read_timeout_threshold

current_epoch = Time.new.to_i
log "This scenario took: #{current_epoch - @scenario_start_time} seconds"

# Check if the scenario failed due to a Net::ReadTimeout
if scenario.failed?
begin
if web_session_is_active?
handle_screenshot_and_relog(scenario, current_epoch)
else
warn 'There is no active web session; unable to take a screenshot or relog.'
if scenario.exception.is_a?(Net::ReadTimeout)
increase_read_timeout_count
log_server_response_time
else
begin
if web_session_is_active?
handle_screenshot_and_relog(scenario, current_epoch)
else
warn 'There is no active web session; unable to take a screenshot or relog.'
end
ensure
print_server_logs
end
ensure
print_server_logs
end
end

page.instance_variable_set(:@touched, false) if Capybara::Session.instance_created?
end

Expand All @@ -157,6 +171,20 @@ def web_session_is_active?
page.has_selector?('header') || page.has_selector?('#username-field')
end

def check_read_timeout_threshold
# Check if the consecutive timeout threshold is reached
if $timeout_failure_counter >= $timeout_threshold
warn "Timeout failure threshold reached, stopping test suite."
exit(1)
end
end

def increase_read_timeout_count
$timeout_failure_counter += 1

warn "Net::ReadTimeout detected! Consecutive ReadTimeouts: #{$timeout_failure_counter}"
end

# Take a screenshot and try to log back at suse manager server
def handle_screenshot_and_relog(scenario, current_epoch)
Dir.mkdir('screenshots') unless File.directory?('screenshots')
Expand Down Expand Up @@ -197,6 +225,7 @@ def relog_and_visit_previous_url
end
rescue Timeout::Error
warn "Timed out while attempting to relog and visit the previous URL: #{current_url}"
increase_read_timeout_count
rescue StandardError => e
warn "An error occurred while relogging and visiting the previous URL: #{e.message}"
end
Expand Down Expand Up @@ -261,6 +290,7 @@ def process_code_coverage

# Create a user for each feature
Before do |scenario|
check_read_timeout_threshold
feature_path = scenario.location.file
$feature_filename = feature_path.split(%r{(\.feature|/)})[-2]
next if get_context('user_created') == true
Expand Down
13 changes: 13 additions & 0 deletions testsuite/features/support/system_monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,16 @@ def channel_synchronization_duration(channel)

duration
end

# Method to check server response time (could be using an HTTP request or ping)
def log_server_response_time
begin
start_time = Time.now
uri = URI.parse("https://#{ENV.fetch('SERVER', nil)}")
Net::HTTP.get_response(uri)
response_time = Time.now - start_time
log "Server response time: #{response_time} seconds"
rescue => e
warn "Error checking server response time: #{e.message}"
end
end
Loading