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:
parent
7b253adc68
commit
226fcd5814
@ -1,5 +1,6 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
|
require_relative '../ruby/envutil'
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'sdbm'
|
require 'sdbm'
|
||||||
@ -33,15 +34,6 @@ class TestSDBM < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def have_fork?
|
|
||||||
begin
|
|
||||||
fork{}
|
|
||||||
true
|
|
||||||
rescue NotImplementedError
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_version
|
def test_version
|
||||||
assert(! SDBM.const_defined?(:VERSION))
|
assert(! SDBM.const_defined?(:VERSION))
|
||||||
end
|
end
|
||||||
@ -76,48 +68,43 @@ class TestSDBM < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def test_s_open_nolock
|
def open_db_child(dbname, *opts)
|
||||||
# sdbm 1.8.0 specific
|
opts = [0644, *opts].map(&:inspect).join(', ')
|
||||||
if not defined? SDBM::NOLOCK
|
args = [EnvUtil.rubybin, "-rsdbm", <<-SRC, dbname]
|
||||||
return
|
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
|
end
|
||||||
return unless have_fork? # snip this test
|
end
|
||||||
|
|
||||||
pid = fork() {
|
def test_s_open_nolock
|
||||||
assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
|
dbname = "#{@tmpdir}/#{@prefix}"
|
||||||
SDBM::NOLOCK))
|
|
||||||
sleep 2
|
open_db_child(dbname, SDBM::NOLOCK) do
|
||||||
}
|
|
||||||
sleep 1
|
|
||||||
begin
|
|
||||||
sdbm2 = nil
|
|
||||||
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
|
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
|
end
|
||||||
|
|
||||||
p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
|
p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
|
||||||
|
|
||||||
pid = fork() {
|
open_db_child(dbname) do
|
||||||
assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
|
|
||||||
sleep 2
|
|
||||||
}
|
|
||||||
begin
|
|
||||||
sleep 1
|
|
||||||
sdbm2 = nil
|
|
||||||
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
|
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
|
||||||
# this test is failed on Cygwin98 (???)
|
# this test is failed on Cygwin98 (???)
|
||||||
assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
|
SDBM.open(dbname, 0644, SDBM::NOLOCK) {|sdbm|
|
||||||
SDBM::NOLOCK))
|
assert_instance_of(SDBM, sdbm)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ensure
|
|
||||||
Process.wait pid
|
|
||||||
sdbm2.close if sdbm2
|
|
||||||
end
|
end
|
||||||
end
|
end if defined? SDBM::NOLOCK # sdbm 1.8.0 specific
|
||||||
|
|
||||||
def test_s_open_error
|
def test_s_open_error
|
||||||
skip "doesn't support to avoid read access by owner on Windows" if /mswin|mingw/ =~ RUBY_PLATFORM
|
skip "doesn't support to avoid read access by owner on Windows" if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user