slyphon-zookeeper 0.3.0-java → 0.8.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/spec_helper.rb CHANGED
@@ -9,34 +9,57 @@ gem 'flexmock', '~> 0.8.11'
9
9
  require 'flexmock'
10
10
  require 'zookeeper'
11
11
 
12
- Zookeeper.logger = Logger.new(File.expand_path('../../test.log', __FILE__)).tap do |log|
13
- log.level = Logger::DEBUG
12
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }
13
+
14
+ if ENV['ZKRB_DEBUG']
15
+ Zookeeper.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
16
+ Zookeeper.set_debug_level(4)
17
+ else
18
+ Zookeeper.logger = Logger.new(File.expand_path('../../test.log', __FILE__)).tap do |log|
19
+ log.level = Logger::DEBUG
20
+ end
14
21
  end
15
22
 
16
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].sort.each { |f| require(f) }
23
+ if ENV['ZKRB_NOLOG']
24
+ Zookeeper.logger.level = Logger::FATAL
25
+ Zookeeper.set_debug_level(0)
26
+ end
27
+
28
+ module ZookeeperSpecHeleprs
29
+ class TimeoutError < StandardError; end
17
30
 
18
- # NOTE: this is a useful debugging setup. have our logs and the low-level C
19
- # logging statements both go to stderr. to use, comment the above and uncomment
20
- # below
31
+ def logger
32
+ Zookeeper.logger
33
+ end
21
34
 
22
- # Zookeeper.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
23
- # Zookeeper.set_debug_level(4)
35
+ # method to wait until block passed returns true or timeout (default is 10 seconds) is reached
36
+ # raises TiemoutError on timeout
37
+ def wait_until(timeout=10)
38
+ time_to_stop = Time.now + timeout
39
+ while true
40
+ rval = yield
41
+ return rval if rval
42
+ raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
43
+ Thread.pass
44
+ end
45
+ end
24
46
 
25
- def logger
26
- Zookeeper.logger
47
+ # inverse of wait_until
48
+ def wait_while(timeout=10)
49
+ time_to_stop = Time.now + timeout
50
+ while true
51
+ rval = yield
52
+ return rval unless rval
53
+ raise TimeoutError, "timeout of #{timeout}s exceeded" if Time.now > time_to_stop
54
+ Thread.pass
55
+ end
56
+ end
27
57
  end
28
58
 
29
59
  RSpec.configure do |config|
30
60
  config.mock_with :flexmock
61
+ config.include ZookeeperSpecHeleprs
62
+ config.extend ZookeeperSpecHeleprs
31
63
  end
32
64
 
33
65
 
34
- # method to wait until block passed returns true or timeout (default is 10 seconds) is reached
35
- def wait_until(timeout=10, &block)
36
- time_to_stop = Time.now + timeout
37
- until yield do
38
- break if Time.now > time_to_stop
39
- sleep 0.3
40
- end
41
- end
42
-