Permalink
Browse files

Merge pull request #212 from wolcanus/master

Adding logger to EM stop
  • Loading branch information...
2 parents 27c45a5 + ffd17f0 commit f36216efbf0f93a6d0488ecb8fd95c5948ae27cf @dj2 dj2 committed Oct 16, 2012
Showing with 20 additions and 2 deletions.
  1. +8 −2 lib/goliath/server.rb
  2. +12 −0 spec/unit/server_spec.rb
View
@@ -71,8 +71,8 @@ def initialize(address = DEFAULT_ADDRESS, port = DEFAULT_PORT)
def start(&blk)
EM.epoll
EM.synchrony do
- trap("INT") { EM.stop }
- trap("TERM") { EM.stop }
+ trap("INT") { stop }
+ trap("TERM") { stop }
if RUBY_PLATFORM !~ /mswin|mingw/
trap("HUP") { load_config(options[:config]) }
@@ -105,6 +105,12 @@ def start(&blk)
end
end
+ # Stops the server running.
+ def stop
+ logger.info('Stopping server...')
+ EM.stop
+ end
+
# Loads a configuration file
#
# @param file [String] The file to load, if not set will use the basename of $0
View
@@ -103,6 +103,18 @@
end
end
+ describe 'stop' do
+ it 'logs when receives TERM signal' do
+ EM.run do
+ logger = mock('logger')
+ logger.should_receive(:info).with('Stopping server...')
+ @s.logger = logger
+ @s.start
+ @s.stop
+ end
+ end
+ end
+
context 'config parsing' do
context 'environment' do
after(:all) do

0 comments on commit f36216e

Please sign in to comment.