Commit ba8c55ee authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'ml-simulate-slow-connection' into 'master'

Add the ability to simulate a slow connection

See merge request gitlab-org/gitlab!20516
parents a2d02092 5d5262ca
......@@ -156,6 +156,8 @@ module QA
def perform(&block)
visit(url)
simulate_slow_connection if Runtime::Env.simulate_slow_connection?
page_class.validate_elements_present!
if QA::Runtime::Env.qa_cookies
......@@ -178,6 +180,28 @@ module QA
def clear!
visit(url)
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
......
......@@ -261,6 +261,22 @@ module QA
ENV['QA_RUNTIME_SCENARIO_ATTRIBUTES']
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
ENV.fetch('GITLAB_QA_LOOP_RUNNER_MINUTES', 1).to_i
end
......
......@@ -62,7 +62,7 @@ RSpec.configure do |config|
# show exception that triggers a retry if verbose_retry is set to true
config.display_try_failure_messages = true
if ENV['CI']
if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
config.around do |example|
retry_times = example.metadata.key?(:quarantine) ? 1 : 2
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