1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test_sdbm.rb: open_db_child

* test/sdbm/test_sdbm.rb (TestSDBM#open_db_child): open the db in a
  child process and handshake using popen.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-19 07:47:36 +00:00
parent 7b253adc68
commit 226fcd5814

View file

@ -1,5 +1,6 @@
require 'test/unit'
require 'tmpdir'
require_relative '../ruby/envutil'
begin
require 'sdbm'
@ -33,15 +34,6 @@ class TestSDBM < Test::Unit::TestCase
end
end
def have_fork?
begin
fork{}
true
rescue NotImplementedError
false
end
end
def test_version
assert(! SDBM.const_defined?(:VERSION))
end
@ -76,48 +68,43 @@ class TestSDBM < Test::Unit::TestCase
end
=end
def test_s_open_nolock
# sdbm 1.8.0 specific
if not defined? SDBM::NOLOCK
return
def open_db_child(dbname, *opts)
opts = [0644, *opts].map(&:inspect).join(', ')
args = [EnvUtil.rubybin, "-rsdbm", <<-SRC, dbname]
STDOUT.sync = true
gdbm = SDBM.open(ARGV.shift, #{opts})
puts sdbm.class
gets
SRC
IO.popen(args, "r+") do |f|
dbclass = f.gets
assert_equal("SDBM", dbclass.chomp)
yield
end
return unless have_fork? # snip this test
end
pid = fork() {
assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
SDBM::NOLOCK))
sleep 2
}
sleep 1
begin
sdbm2 = nil
def test_s_open_nolock
dbname = "#{@tmpdir}/#{@prefix}"
open_db_child(dbname, SDBM::NOLOCK) do
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
SDBM.open(dbname, 0644) {|sdbm|
assert_instance_of(SDBM, sdbm)
}
}
ensure
Process.wait pid
sdbm2.close if sdbm2
end
p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
pid = fork() {
assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
sleep 2
}
begin
sleep 1
sdbm2 = nil
open_db_child(dbname) do
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
# this test is failed on Cygwin98 (???)
assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
SDBM::NOLOCK))
SDBM.open(dbname, 0644, SDBM::NOLOCK) {|sdbm|
assert_instance_of(SDBM, sdbm)
}
}
ensure
Process.wait pid
sdbm2.close if sdbm2
end
end
end if defined? SDBM::NOLOCK # sdbm 1.8.0 specific
def test_s_open_error
skip "doesn't support to avoid read access by owner on Windows" if /mswin|mingw/ =~ RUBY_PLATFORM