HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/openproject/spec/support/rspec_retry.rb
require 'rspec/retry'
require 'retriable'

##
# Enable specs to mark metadata retry: <count> to retry that given example
# immediately after it fails.
#
# This DOES NOT retry all specs by default.
RSpec.configure do |config|
  ##
  # Print verbose information on when an example is being retried
  # and print the exception that causes a retry
  config.verbose_retry = true
  config.display_try_failure_messages = true

  ##
  # By default, do not retry specs
  config.default_retry_count = 0

  ##
  # Retry JS feature specs, but not during single runs
  if ENV['CI']
    config.around :each, :js do |ex|
      ex.run_with_retry retry: 2
    end
  end
end

##
# Allow specific code blocks to retry on specific errors
Retriable.configure do |c|
  c.intervals = [1, 1, 2]
end

##
# Helper to pass options to retriable while logging
# failures
def retry_block(args: {}, screenshot: false, &block)
  log_errors = Proc.new do |exception, try, elapsed_time, next_interval|
    $stderr.puts <<-EOS.strip_heredoc
    #{exception.class}: '#{exception.message}'
    #{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try.
    EOS

    if screenshot
      begin
        Capybara::Screenshot.screenshot_and_save_page
      rescue StandardError => e
        $stderr.puts "Failed to take screenshot in retry_block: #{e} #{e.message}"
      end
    end
  end

  Retriable.retriable(args.merge(on_retry: log_errors), &block)
end