diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 09:40:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 09:40:42 +0000 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/support/capybara_slow_finder.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) | |
download | gitlab-ce-ee664acb356f8123f4f6b00b73c1e1cf0866c7fb.tar.gz |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/support/capybara_slow_finder.rb')
-rw-r--r-- | spec/support/capybara_slow_finder.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/support/capybara_slow_finder.rb b/spec/support/capybara_slow_finder.rb new file mode 100644 index 00000000000..975ddd52c1f --- /dev/null +++ b/spec/support/capybara_slow_finder.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Capybara + MESSAGE = <<~MSG + Timeout (%{timeout}s) reached while running a waiting Capybara finder. + Consider using a non-waiting finder. + + See https://www.cloudbees.com/blog/faster-rails-tests + MSG + + module Node + class Base + # Inspired by https://github.com/ngauthier/capybara-slow_finder_errors + module SlowFinder + def synchronize(seconds = nil, errors: nil) + start_time = Gitlab::Metrics::System.monotonic_time + + super + rescue Capybara::ElementNotFound => e + seconds ||= Capybara.default_max_wait_time + + raise e unless seconds > 0 && Gitlab::Metrics::System.monotonic_time - start_time > seconds + + message = format(MESSAGE, timeout: seconds) + raise e, "#{$!}\n\n#{message}", e.backtrace + end + end + + prepend SlowFinder + end + end +end |