Commit f5f5969f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch...

Merge branch '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 and fix a flaky test

Closes #11224

See merge request gitlab-org/gitlab-ee!11200
parents 60d60ff8 340f164e
...@@ -80,11 +80,11 @@ describe 'Projects > Audit Events', :js do ...@@ -80,11 +80,11 @@ describe 'Projects > Audit Events', :js do
find('.ic-remove').click find('.ic-remove').click
end end
wait_for_all_requests
visit project_audit_events_path(project) visit project_audit_events_path(project)
expect(page).to have_content('Remove deploy key') wait_for('Audit event background creation job is done', polling_interval: 0.5, reload: true) do
page.has_content?('Remove deploy key', wait: 0)
end
end end
end end
......
...@@ -85,6 +85,7 @@ RSpec.configure do |config| ...@@ -85,6 +85,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 ...@@ -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
......
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
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