Commit 5d5262ca authored by Mark Lapierre's avatar Mark Lapierre Committed by Sanad Liaquat

Add the ability to simulate a slow connection

Can set QA_SIMULATE_SLOW_CONNECTION to simulate a slow connection
QA_SLOW_CONNECTION_LATENCY_MS sets additional latency in ms
QA_SLOW_CONNECTION_THROUGHPUT_KBPS sets the maximum throughput in kbps
parent a2d02092
...@@ -156,6 +156,8 @@ module QA ...@@ -156,6 +156,8 @@ module QA
def perform(&block) def perform(&block)
visit(url) visit(url)
simulate_slow_connection if Runtime::Env.simulate_slow_connection?
page_class.validate_elements_present! page_class.validate_elements_present!
if QA::Runtime::Env.qa_cookies if QA::Runtime::Env.qa_cookies
...@@ -178,6 +180,28 @@ module QA ...@@ -178,6 +180,28 @@ module QA
def clear! def clear!
visit(url) visit(url)
reset_session! reset_session!
@network_conditions_configured = false
end
private
def simulate_slow_connection
return if @network_conditions_configured
QA::Runtime::Logger.info(
<<~MSG.tr("\n", " ")
Simulating a slow connection with additional latency
of #{Runtime::Env.slow_connection_latency} ms and a maximum
throughput of #{Runtime::Env.slow_connection_throughput} kbps
MSG
)
Capybara.current_session.driver.browser.network_conditions = {
latency: Runtime::Env.slow_connection_latency,
throughput: Runtime::Env.slow_connection_throughput * 1000
}
@network_conditions_configured = true
end end
end end
end end
......
...@@ -261,6 +261,22 @@ module QA ...@@ -261,6 +261,22 @@ module QA
ENV['QA_RUNTIME_SCENARIO_ATTRIBUTES'] ENV['QA_RUNTIME_SCENARIO_ATTRIBUTES']
end end
def disable_rspec_retry?
enabled?(ENV['QA_DISABLE_RSPEC_RETRY'], default: false)
end
def simulate_slow_connection?
enabled?(ENV['QA_SIMULATE_SLOW_CONNECTION'], default: false)
end
def slow_connection_latency
ENV.fetch('QA_SLOW_CONNECTION_LATENCY_MS', 2000).to_i
end
def slow_connection_throughput
ENV.fetch('QA_SLOW_CONNECTION_THROUGHPUT_KBPS', 32).to_i
end
def gitlab_qa_loop_runner_minutes def gitlab_qa_loop_runner_minutes
ENV.fetch('GITLAB_QA_LOOP_RUNNER_MINUTES', 1).to_i ENV.fetch('GITLAB_QA_LOOP_RUNNER_MINUTES', 1).to_i
end end
......
...@@ -62,7 +62,7 @@ RSpec.configure do |config| ...@@ -62,7 +62,7 @@ RSpec.configure do |config|
# show exception that triggers a retry if verbose_retry is set to true # show exception that triggers a retry if verbose_retry is set to true
config.display_try_failure_messages = true config.display_try_failure_messages = true
if ENV['CI'] if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
config.around do |example| config.around do |example|
retry_times = example.metadata.key?(:quarantine) ? 1 : 2 retry_times = example.metadata.key?(:quarantine) ? 1 : 2
example.run_with_retry retry: retry_times example.run_with_retry retry: retry_times
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment