# frozen_string_literal: true

# Helper for testing threaded code.
QUE_TEST_TIMEOUT ||= 2
def sleep_until(timeout = QUE_TEST_TIMEOUT)
  deadline = Time.now + timeout
  loop do
    break if yield
    raise "Thing never happened!" if Time.now > deadline
    sleep 0.01
  end
end

def suppress_warnings
  original_verbosity, $VERBOSE = $VERBOSE, nil
  yield
ensure
  $VERBOSE = original_verbosity
end

# frozen_string_literal: true

# Travis seems to freeze the VM the tests run in sometimes, so bump up the limit
# when running in CI.
QUE_SLEEP_UNTIL_TIMEOUT = ENV['CI'] ? 10 : 2

# Helper for testing threaded code.
def sleep_until(timeout = QUE_SLEEP_UNTIL_TIMEOUT)
  deadline = Time.now + timeout
  loop do
    break if yield
    if Time.now > deadline
      puts "sleep_until timeout reached!"
      raise "sleep_until timeout reached!"
    end
    sleep 0.01
  end
end

def suppress_warnings
  original_verbosity, $VERBOSE = $VERBOSE, nil
  yield
ensure
  $VERBOSE = original_verbosity
end

Make sleep_until timeout more forgiving on Travis.
Make sleep_until timeout more forgiving on Travis.
