From 60a5273d7d49f074a75312642bcf2159b8a30ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 13 Apr 2017 18:31:33 +0200 Subject: [PATCH 1/2] Wait for AJAX requests at the JS level in addition to wait for requests at the middleware level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hopefully, this can solve transient failures such as https://gitlab.com/gitlab-org/gitlab-ce/issues/29836. Signed-off-by: Rémy Coutable --- spec/support/wait_for_requests.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/support/wait_for_requests.rb b/spec/support/wait_for_requests.rb index 0bfa7f72ff8c..73da23391ee8 100644 --- a/spec/support/wait_for_requests.rb +++ b/spec/support/wait_for_requests.rb @@ -1,11 +1,15 @@ +require_relative './wait_for_ajax' + module WaitForRequests extend self + include WaitForAjax # This is inspired by http://www.salsify.com/blog/engineering/tearing-capybara-ajax-tests def wait_for_requests_complete Gitlab::Testing::RequestBlockerMiddleware.block_requests! wait_for('pending AJAX requests complete') do - Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? + Gitlab::Testing::RequestBlockerMiddleware.num_active_requests.zero? && + finished_all_ajax_requests? end ensure Gitlab::Testing::RequestBlockerMiddleware.allow_requests! -- GitLab From 11ad7444be81b656e8e2142ae24be0245be60a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Wed, 26 Apr 2017 12:40:52 +0200 Subject: [PATCH 2/2] Ensure Spinach features with JS waits for requests to complete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- features/support/env.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index 06c804b1db7f..92d13bea4b69 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -10,7 +10,7 @@ Knapsack::Adapters::SpinachAdapter.bind end -%w(select2_helper test_env repo_helpers wait_for_ajax sidekiq).each do |f| +%w(select2_helper test_env repo_helpers wait_for_ajax wait_for_requests sidekiq).each do |f| require Rails.root.join('spec', 'support', f) end @@ -30,6 +30,13 @@ include FactoryGirl::Syntax::Methods end +Spinach.hooks.after_feature do |feature_data| + if feature_data.scenarios.flat_map(&:tags).include?('javascript') + include WaitForRequests + wait_for_requests_complete + end +end + module StdoutReporterWithScenarioLocation # Override the standard reporter to show filename and line number next to each # scenario for easy, focused re-runs -- GitLab