Sha256: 1952127b2ec1e448072c65a2f08c67d6f789e16c3e1d0766b42e1036c7530ccc

Contents?: true

Size: 1.11 KB

Versions: 88

Compression:

Stored size: 1.11 KB

Contents

module WaitForHelper
  # Wait for a condition to be met
  #
  # @example
  #   # Perform threaded operation
  #   wait_for("enough probe calls") { probe.calls >= 2 }
  #   # Assert on result
  #
  # @param name [String] The name of the condition to check. Used in the
  #   error when it fails.
  # @yield Assertion to check.
  # @yieldreturn [Boolean] True/False value that indicates if the condition
  #   is met.
  # @raise [StandardError] Raises error if the condition is not met after 5
  #   seconds, 5_000 tries.
  def wait_for(name)
    max_wait = 5_000
    i = 0
    error = nil
    while i < max_wait
      begin
        result = yield
        break if result
      rescue Exception => e # rubocop:disable Lint/RescueException
        # Capture error so we know if it exited with an error
        error = e
      ensure
        i += 1
        sleep 0.001
      end
    end

    return unless i >= max_wait
    error_message =
      if error
        "\nError: #{error.class}: #{error.message}\n#{error.backtrace.join("\n")}"
      end
    raise "Waited 5 seconds for #{name} condition, but was not met.#{error_message}"
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
appsignal-3.3.11-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.11 spec/support/helpers/wait_for_helper.rb
appsignal-3.4.0-java spec/support/helpers/wait_for_helper.rb
appsignal-3.4.0 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.10-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.10 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.9-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.9 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.8-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.8 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.7-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.7 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.6-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.6 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.5-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.5 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.4-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.4 spec/support/helpers/wait_for_helper.rb
appsignal-3.3.3-java spec/support/helpers/wait_for_helper.rb
appsignal-3.3.3 spec/support/helpers/wait_for_helper.rb