1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/xmlrpc/webrick_testing.rb
mneumann 597e0c74ba added new test case (which spawn off a webrick XML-RPC server)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-11-16 14:07:15 +00:00

37 lines
848 B
Ruby

require 'timeout'
module WEBrick_Testing
class DummyLog < WEBrick::BasicLog
def initialize() super(self) end
def <<(*args) end
end
def start_server(config={})
raise "already started" if @__server_pid or @__started
trap('HUP') { @__started = true }
@__server_pid = fork do
w = WEBrick::HTTPServer.new(
{
:Logger => DummyLog.new,
:AccessLog => [],
:StartCallback => proc { Process.kill('HUP', Process.ppid) }
}.update(config))
yield w
trap('INT') { w.shutdown }
w.start
exit
end
Timeout.timeout(5) {
nil until @__started # wait until the server is ready
}
end
def stop_server
Process.kill('INT', @__server_pid)
@__server_pid = nil
@__started = false
Process.wait
raise unless $?.success?
end
end