Merge branch 'ce-11224-flaky-test-projects-audit-events-adding-an-ssh-key-appears-in-the-project-s-audit-events-ee-spec-features-projects-audit_events_spec' into 'master'
Introduce the wait_for helper for system tests See merge request gitlab-org/gitlab-ce!27483
This commit is contained in:
commit
f1b3db3cf2
3 changed files with 21 additions and 14 deletions
|
@ -83,6 +83,7 @@ RSpec.configure do |config|
|
||||||
config.include Devise::Test::IntegrationHelpers, type: :feature
|
config.include Devise::Test::IntegrationHelpers, type: :feature
|
||||||
config.include LoginHelpers, type: :feature
|
config.include LoginHelpers, type: :feature
|
||||||
config.include SearchHelpers, type: :feature
|
config.include SearchHelpers, type: :feature
|
||||||
|
config.include WaitHelpers, type: :feature
|
||||||
config.include EmailHelpers, :mailer, type: :mailer
|
config.include EmailHelpers, :mailer, type: :mailer
|
||||||
config.include Warden::Test::Helpers, type: :request
|
config.include Warden::Test::Helpers, type: :request
|
||||||
config.include Gitlab::Routing, type: :routing
|
config.include Gitlab::Routing, type: :routing
|
||||||
|
|
|
@ -50,20 +50,6 @@ module WaitForRequests
|
||||||
finished_all_vue_resource_requests?
|
finished_all_vue_resource_requests?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Waits until the passed block returns true
|
|
||||||
def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01)
|
|
||||||
wait_until = Time.now + max_wait_time.seconds
|
|
||||||
loop do
|
|
||||||
break if yield
|
|
||||||
|
|
||||||
if Time.now > wait_until
|
|
||||||
raise "Condition not met: #{condition_name}"
|
|
||||||
else
|
|
||||||
sleep(polling_interval)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def finished_all_vue_resource_requests?
|
def finished_all_vue_resource_requests?
|
||||||
Capybara.page.evaluate_script('window.activeVueResources || 0').zero?
|
Capybara.page.evaluate_script('window.activeVueResources || 0').zero?
|
||||||
end
|
end
|
||||||
|
|
20
spec/support/helpers/wait_helpers.rb
Normal file
20
spec/support/helpers/wait_helpers.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module WaitHelpers
|
||||||
|
extend self
|
||||||
|
|
||||||
|
# Waits until the passed block returns true
|
||||||
|
def wait_for(condition_name, max_wait_time: Capybara.default_max_wait_time, polling_interval: 0.01, reload: false)
|
||||||
|
wait_until = Time.now + max_wait_time.seconds
|
||||||
|
loop do
|
||||||
|
result = yield
|
||||||
|
break if result
|
||||||
|
|
||||||
|
page.refresh if reload
|
||||||
|
|
||||||
|
if Time.now > wait_until
|
||||||
|
raise "Condition not met: #{condition_name}"
|
||||||
|
else
|
||||||
|
sleep(polling_interval)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue