2004-11-16 09:07:15 -05:00
|
|
|
require 'timeout'
|
|
|
|
|
2013-11-03 06:41:53 -05:00
|
|
|
module TestXMLRPC
|
2004-11-16 09:07:15 -05:00
|
|
|
module WEBrick_Testing
|
|
|
|
class DummyLog < WEBrick::BasicLog
|
|
|
|
def initialize() super(self) end
|
|
|
|
def <<(*args) end
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-11-16 09:07:15 -05:00
|
|
|
def start_server(config={})
|
2010-01-25 18:12:50 -05:00
|
|
|
raise "already started" if defined?(@__server) && @__server
|
2004-12-21 11:23:33 -05:00
|
|
|
@__started = false
|
|
|
|
|
2007-12-15 09:51:48 -05:00
|
|
|
@__server_thread = Thread.new {
|
2004-12-21 11:23:33 -05:00
|
|
|
@__server = WEBrick::HTTPServer.new(
|
2009-03-05 22:56:38 -05:00
|
|
|
{
|
2011-08-03 11:38:44 -04:00
|
|
|
:BindAddress => "localhost",
|
2004-11-16 09:07:15 -05:00
|
|
|
:Logger => DummyLog.new,
|
|
|
|
:AccessLog => [],
|
2004-12-21 11:23:33 -05:00
|
|
|
:StartCallback => proc { @__started = true }
|
2004-11-16 09:07:15 -05:00
|
|
|
}.update(config))
|
2009-03-05 22:56:38 -05:00
|
|
|
yield @__server
|
2011-02-12 19:56:40 -05:00
|
|
|
begin
|
|
|
|
@__server.start
|
|
|
|
rescue IOError => e
|
|
|
|
assert_match(/closed/, e.message)
|
|
|
|
ensure
|
|
|
|
@__started = false
|
|
|
|
end
|
2004-12-21 11:23:33 -05:00
|
|
|
}
|
2004-11-16 09:07:15 -05:00
|
|
|
|
|
|
|
Timeout.timeout(5) {
|
2005-10-05 12:15:16 -04:00
|
|
|
Thread.pass until @__started # wait until the server is ready
|
2004-11-16 09:07:15 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_server
|
2013-11-03 06:26:58 -05:00
|
|
|
return if !defined?(@__server) || !@__server
|
2004-12-21 11:23:33 -05:00
|
|
|
Timeout.timeout(5) {
|
|
|
|
@__server.shutdown
|
2005-10-05 12:15:16 -04:00
|
|
|
Thread.pass while @__started # wait until the server is down
|
2004-12-21 11:23:33 -05:00
|
|
|
}
|
2007-12-15 09:51:48 -05:00
|
|
|
@__server_thread.join
|
2004-12-21 11:23:33 -05:00
|
|
|
@__server = nil
|
2004-11-16 09:07:15 -05:00
|
|
|
end
|
|
|
|
end
|
2013-11-03 06:41:53 -05:00
|
|
|
end
|