2004-11-16 17:07:15 +03:00
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
module WEBrick_Testing
|
|
|
|
class DummyLog < WEBrick::BasicLog
|
|
|
|
def initialize() super(self) end
|
|
|
|
def <<(*args) end
|
|
|
|
end
|
2009-03-06 06:56:38 +03:00
|
|
|
|
2004-11-16 17:07:15 +03:00
|
|
|
def start_server(config={})
|
2004-12-21 19:23:33 +03:00
|
|
|
raise "already started" if @__server
|
|
|
|
@__started = false
|
|
|
|
|
2007-12-15 17:51:48 +03:00
|
|
|
@__server_thread = Thread.new {
|
2004-12-21 19:23:33 +03:00
|
|
|
@__server = WEBrick::HTTPServer.new(
|
2009-03-06 06:56:38 +03:00
|
|
|
{
|
2004-11-16 17:07:15 +03:00
|
|
|
:Logger => DummyLog.new,
|
|
|
|
:AccessLog => [],
|
2004-12-21 19:23:33 +03:00
|
|
|
:StartCallback => proc { @__started = true }
|
2004-11-16 17:07:15 +03:00
|
|
|
}.update(config))
|
2009-03-06 06:56:38 +03:00
|
|
|
yield @__server
|
2004-12-21 19:23:33 +03:00
|
|
|
@__server.start
|
|
|
|
@__started = false
|
|
|
|
}
|
2004-11-16 17:07:15 +03:00
|
|
|
|
|
|
|
Timeout.timeout(5) {
|
2005-10-05 20:15:16 +04:00
|
|
|
Thread.pass until @__started # wait until the server is ready
|
2004-11-16 17:07:15 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_server
|
2004-12-21 19:23:33 +03:00
|
|
|
Timeout.timeout(5) {
|
|
|
|
@__server.shutdown
|
2005-10-05 20:15:16 +04:00
|
|
|
Thread.pass while @__started # wait until the server is down
|
2004-12-21 19:23:33 +03:00
|
|
|
}
|
2007-12-15 17:51:48 +03:00
|
|
|
@__server_thread.join
|
2004-12-21 19:23:33 +03:00
|
|
|
@__server = nil
|
2004-11-16 17:07:15 +03:00
|
|
|
end
|
|
|
|
end
|