mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/webrick/server.rb: Invoke setup_shutdown_pipe in start method
instead of listen method. [ruby-core:68476] [Bug #10956] Reported by Shintaro Kojima. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
acc17bfc0f
commit
ab0a64e1c8
3 changed files with 36 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
Tue Mar 10 20:03:41 2015 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/webrick/server.rb: Invoke setup_shutdown_pipe in start method
|
||||
instead of listen method.
|
||||
[ruby-core:68476] [Bug #10956] Reported by Shintaro Kojima.
|
||||
|
||||
Tue Mar 10 17:27:27 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* thread.c (thread_join): Fixnum (except TAG_FATAL) and
|
||||
|
|
|
@ -131,7 +131,6 @@ module WEBrick
|
|||
|
||||
def listen(address, port)
|
||||
@listeners += Utils::create_listeners(address, port)
|
||||
setup_shutdown_pipe
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -159,6 +158,8 @@ module WEBrick
|
|||
raise ServerError, "already started." if @status != :Stop
|
||||
server_type = @config[:ServerType] || SimpleServer
|
||||
|
||||
setup_shutdown_pipe
|
||||
|
||||
server_type.start{
|
||||
@logger.info \
|
||||
"#{self.class}#start: pid=#{$$} port=#{@config[:Port]}"
|
||||
|
@ -330,6 +331,7 @@ module WEBrick
|
|||
|
||||
def cleanup_shutdown_pipe(shutdown_pipe)
|
||||
@shutdown_pipe = nil
|
||||
return if !shutdown_pipe
|
||||
shutdown_pipe.each {|io|
|
||||
if !io.closed?
|
||||
begin
|
||||
|
|
|
@ -97,7 +97,7 @@ class TestWEBrickServer < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_restart
|
||||
def test_restart_after_shutdown
|
||||
address = '127.0.0.1'
|
||||
port = 0
|
||||
log = []
|
||||
|
@ -128,4 +128,30 @@ class TestWEBrickServer < Test::Unit::TestCase
|
|||
assert_join_threads([client_thread, server_thread])
|
||||
assert_equal([], log)
|
||||
end
|
||||
|
||||
def test_restart_after_stop
|
||||
log = Object.new
|
||||
class << log
|
||||
include Test::Unit::Assertions
|
||||
def <<(msg)
|
||||
flunk "unexpected log: #{msg.inspect}"
|
||||
end
|
||||
end
|
||||
warn_flunk = WEBrick::Log.new(log, WEBrick::BasicLog::WARN)
|
||||
server = WEBrick::HTTPServer.new(
|
||||
:BindAddress => '0.0.0.0',
|
||||
:Port => 0,
|
||||
:Logger => warn_flunk)
|
||||
2.times {
|
||||
server_thread = Thread.start {
|
||||
server.start
|
||||
}
|
||||
client_thread = Thread.start {
|
||||
sleep 0.1 until server.status == :Running || !server_thread.status
|
||||
server.stop
|
||||
sleep 0.1 until server.status == :Stop || !server_thread.status
|
||||
}
|
||||
assert_join_threads([client_thread, server_thread])
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue