Skip to content
Browse files

adding timeouts to all the server specs

  • Loading branch information...
1 parent 9f44e31 commit d097c5f2104bb8c505797fe63c8747a598934267 @TwP committed Feb 7, 2012
Showing with 16 additions and 12 deletions.
  1. +16 −12 spec/server_spec.rb
View
28 spec/server_spec.rb
@@ -2,6 +2,12 @@
require File.expand_path('../spec_helper', __FILE__)
describe Servolux::Server do
+
+ def pass_until( seconds = 5 )
+ start = Time.now
+ Thread.pass until (Time.now - start) > seconds or yield
+ end
+
base = Class.new(Servolux::Server) do
def initialize( &block )
super('Test Server', :logger => Logging.logger['Servolux'], &block)
@@ -23,52 +29,51 @@ def run() sleep; end
test(?e, @server.pid_file).should be_false
t = Thread.new {@server.startup}
- Thread.pass until @server.running? and t.status == 'sleep'
+ pass_until { @server.running? and t.status == 'sleep' }
test(?e, @server.pid_file).should be_true
@server.shutdown
- Thread.pass until t.status == false
+ pass_until { t.status == false }
test(?e, @server.pid_file).should be_false
end
it 'generates a PID file with mode rw-r----- by default' do
t = Thread.new {@server.startup}
- Thread.pass until @server.running? and t.status == 'sleep'
+ pass_until { @server.running? and t.status == 'sleep' }
test(?e, @server.pid_file).should be_true
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Starting)
(File.stat(@server.pid_file).mode & 0777).should be == 0640
@server.shutdown
- Thread.pass until t.status == false
+ pass_until { t.status == false }
test(?e, @server.pid_file).should be_false
end
it 'generates PID file with the specified permissions' do
@server.pid_file_mode = 0400
t = Thread.new {@server.startup}
- Thread.pass until @server.running? and t.status == 'sleep'
+ pass_until { @server.running? and t.status == 'sleep' }
test(?e, @server.pid_file).should be_true
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Starting)
(File.stat(@server.pid_file).mode & 0777).should be == 0400
@server.shutdown
- Thread.pass until t.status == false
+ pass_until { t.status == false }
test(?e, @server.pid_file).should be_false
end
it 'shuts down gracefully when signaled' do
t = Thread.new {@server.startup}
- Thread.pass until @server.running? and t.status == 'sleep'
+ pass_until { @server.running? and t.status == 'sleep' }
@server.should be_running
ENV['TRAVIS'] ? @server.int : Process.kill('INT', $$)
- start = Time.now
- Thread.pass until t.status == false or (Time.now - start) > 5
+ pass_until { t.status == false }
@server.should_not be_running
end
@@ -80,7 +85,7 @@ def usr2() logger.info 'usr2 was called'; end
end
t = Thread.new {@server.startup}
- Thread.pass until @server.running? and t.status == 'sleep'
+ pass_until { @server.running? and t.status == 'sleep' }
@log_output.readline
Process.kill('USR1', $$)
@@ -93,8 +98,7 @@ def usr2() logger.info 'usr2 was called'; end
@log_output.readline.strip.should be == 'INFO Servolux : usr2 was called'
ENV['TRAVIS'] ? @server.term : Process.kill('TERM', $$)
- start = Time.now
- sleep 0.1 until t.status == false or (Time.now - start) > 5
+ pass_until { t.status == false }
@server.should_not be_running
end
end

0 comments on commit d097c5f

Please sign in to comment.
Something went wrong with that request. Please try again.