mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/openssl/test_ssl.rb: use Process.kill to kill child process
instead of waiting for closing popen-ed IO. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
86d21234a4
commit
f9bdcf5495
2 changed files with 24 additions and 17 deletions
|
@ -49,30 +49,29 @@ Socket.do_not_reverse_lookup = true
|
|||
tcps = TCPServer.new("0.0.0.0", port)
|
||||
ssls = OpenSSL::SSL::SSLServer.new(tcps, ctx)
|
||||
ssls.start_immediately = start_immediately
|
||||
ssock = nil
|
||||
|
||||
Thread.start{
|
||||
while line = $stdin.gets
|
||||
if /STARTTLS/ =~ line
|
||||
ssock && ssock.accept
|
||||
end
|
||||
while true
|
||||
$stdin.gets || exit
|
||||
end
|
||||
exit
|
||||
}
|
||||
|
||||
$stdout.sync = true
|
||||
$stdout.puts Process.pid
|
||||
|
||||
loop do
|
||||
s = ssls.accept
|
||||
ssock = s
|
||||
ssl = ssls.accept
|
||||
Thread.start{
|
||||
q = Queue.new
|
||||
th = Thread.start{ s.write(q.shift) while true }
|
||||
while line = s.gets
|
||||
th = Thread.start{ ssl.write(q.shift) while true }
|
||||
while line = ssl.gets
|
||||
if line =~ /^STARTTLS$/
|
||||
ssl.accept
|
||||
next
|
||||
end
|
||||
q.push(line)
|
||||
end
|
||||
th.kill
|
||||
s.close unless s.closed?
|
||||
th.kill if q.empty?
|
||||
ssl.close
|
||||
}
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
|
|||
)
|
||||
SSL_SERVER = File.join(File.dirname(__FILE__), "ssl_server.rb")
|
||||
PORT = 20443
|
||||
ITERATIONS = ($0 == __FILE__) ? 100 : 10
|
||||
ITERATIONS = ($0 == __FILE__) ? 100 : 10
|
||||
|
||||
def setup
|
||||
@ca_key = OpenSSL::TestUtils::TEST_KEY_RSA2048
|
||||
|
@ -65,15 +65,23 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
|
|||
server.write(@ca_cert.to_pem)
|
||||
server.write(@svr_cert.to_pem)
|
||||
server.write(@svr_key.to_pem)
|
||||
def server.starttls; self.puts("STARTTLS") end
|
||||
pid = Integer(server.gets)
|
||||
$stderr.printf("%s started: pid=%d\n", SSL_SERVER, pid) if $DEBUG
|
||||
block.call(server)
|
||||
ensure
|
||||
server.close if server
|
||||
if server
|
||||
server.close_write
|
||||
Process.kill(:TERM, pid) rescue nil
|
||||
Process.waitpid(pid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def starttls(ssl)
|
||||
ssl.puts("STARTTLS")
|
||||
ssl.connect
|
||||
end
|
||||
|
||||
def test_connect_and_close
|
||||
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true){
|
||||
sock = TCPSocket.new("127.0.0.1", PORT)
|
||||
|
@ -148,8 +156,7 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
|
|||
assert_equal(str, ssl.gets)
|
||||
}
|
||||
|
||||
s.starttls
|
||||
ssl.connect
|
||||
starttls(ssl)
|
||||
|
||||
ITERATIONS.times{
|
||||
ssl.puts(str)
|
||||
|
@ -177,6 +184,7 @@ class OpenSSL::TestSSL < Test::Unit::TestCase
|
|||
assert_equal(str, ssl.gets)
|
||||
}
|
||||
}
|
||||
ssls.each{|ssl| ssl.close }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue