<commit_before>$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../../ext', __FILE__))
$LOAD_PATH.uniq!

require 'rubygems'

gem 'flexmock', '~> 0.8.11'

require 'flexmock'
require 'zookeeper'

Zookeeper.logger = Logger.new(File.expand_path('../../test.log', __FILE__)).tap do |log|
  log.level = Logger::DEBUG
end

Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }

# NOTE: this is a useful debugging setup. have our logs and the low-level C
# logging statements both go to stderr. to use, comment the above and uncomment
# below

# Zookeeper.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
# Zookeeper.set_debug_level(4)
module ZookeeperSpecHeleprs
  class TimeoutError < StandardError; end

  def logger
    Zookeeper.logger
  end

  # method to wait until block passed returns true or timeout (default is 10 seconds) is reached 
  # raises TiemoutError on timeout
  def wait_until(timeout=10)
    time_to_stop = Time.now + timeout
    while true
      rval = yield
      return rval if rval
      raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
      Thread.pass
    end
  end

  # inverse of wait_until
  def wait_while(timeout=10)
    time_to_stop = Time.now + timeout
    while true
      rval = yield
      return rval unless rval
      raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
      Thread.pass
    end
  end
end<commit_msg>set ENV['ZKRB_DEBUG'] for C-level log output during spec runs<commit_after>$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
$LOAD_PATH.unshift(File.expand_path('../../ext', __FILE__))
$LOAD_PATH.uniq!

require 'rubygems'

gem 'flexmock', '~> 0.8.11'

require 'flexmock'
require 'zookeeper'

Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }

if ENV['ZKRB_DEBUG']
  Zookeeper.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
  Zookeeper.set_debug_level(4)
else
  Zookeeper.logger = Logger.new(File.expand_path('../../test.log', __FILE__)).tap do |log|
    log.level = Logger::DEBUG
  end
end

module ZookeeperSpecHeleprs
  class TimeoutError < StandardError; end

  def logger
    Zookeeper.logger
  end

  # method to wait until block passed returns true or timeout (default is 10 seconds) is reached 
  # raises TiemoutError on timeout
  def wait_until(timeout=10)
    time_to_stop = Time.now + timeout
    while true
      rval = yield
      return rval if rval
      raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
      Thread.pass
    end
  end

  # inverse of wait_until
  def wait_while(timeout=10)
    time_to_stop = Time.now + timeout
    while true
      rval = yield
      return rval unless rval
      raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
      Thread.pass
    end
  end
end
{'fraction_non_alphanumeric': 0.11650153741031773, 'fraction_numerical': 0.007516228220020499, 'mean_word_length': 3.4839203675344566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107657', 'n_tokens_mistral': 1018, 'n_tokens_neox': 982, 'n_words': 271}