Skip to content

Commit

Permalink
adding timeouts to all the server specs
Browse files Browse the repository at this point in the history
  • Loading branch information
TwP committed Feb 7, 2012
1 parent 9f44e31 commit d097c5f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions spec/server_spec.rb
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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', $$)
Expand All @@ -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
Expand Down

0 comments on commit d097c5f

Please sign in to comment.