Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve pidfile reporting and test coverage

 * Output reduced to a single line
 * Integration test added that also suppresses and checks output
  • Loading branch information...
commit edc8b923fa4ea4e3c1ce8778f5ddbc89688bc01b 1 parent b4d7b95
@raggi raggi authored
Showing with 23 additions and 7 deletions.
  1. +2 −7 lib/rack/server.rb
  2. +21 −0 test/spec_server.rb
View
9 lib/rack/server.rb
@@ -325,14 +325,10 @@ def write_pid
def check_pid!
case pidfile_process_status
- when :running
- STDERR.puts "The process is still alive. aborting."
- exit(1)
- when :not_owned
- STDERR.puts "The process is still alive. And owned by another user aborting."
+ when :running, :not_owned
+ $stderr.puts "A server is already running. Check #{options[:pid]}."
exit(1)
when :dead
- STDERR.puts "The process is no longer running. Removing the pid file."
::File.delete(options[:pid])
end
end
@@ -341,7 +337,6 @@ def pidfile_process_status
return :exited unless ::File.exist?(options[:pid])
pid = ::File.read(options[:pid]).to_i
- STDERR.puts "There is already a pid file wrote a by process with pid #{pid}"
Process.kill(0, pid)
:running
rescue Errno::ESRCH
View
21 test/spec_server.rb
@@ -10,6 +10,13 @@ def app
lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['success']] }
end
+ def with_stderr
+ old, $stderr = $stderr, StringIO.new
+ yield $stderr
+ ensure
+ $stderr = old
+ end
+
it "overrides :config if :app is passed in" do
server = Rack::Server.new(:app => "FOO")
server.app.should == "FOO"
@@ -97,4 +104,18 @@ def app
server.send(:pidfile_process_status).should.eql :not_owned
end
+ should "inform the user about existing pidfiles with running processes" do
+ pidfile = Tempfile.open('pidfile') { |f| f.write(1); break f }.path
+ server = Rack::Server.new(:pid => pidfile)
+ with_stderr do |err|
+ should.raise(SystemExit) do
+ server.start
+ end
+ err.rewind
+ output = err.read
+ output.should.match(/already running/)
+ output.should.include? pidfile
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.