[前][次][番号順一覧][スレッド一覧]

ruby-changes:29372

From: nobu <ko1@a...>
Date: Wed, 19 Jun 2013 16:48:22 +0900 (JST)
Subject: [ruby-changes:29372] nobu:r41425 (trunk): test_sdbm.rb: open_db_child

nobu	2013-06-19 16:47:36 +0900 (Wed, 19 Jun 2013)

  New Revision: 41425

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41425

  Log:
    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.

  Modified files:
    trunk/test/sdbm/test_sdbm.rb

Index: test/sdbm/test_sdbm.rb
===================================================================
--- test/sdbm/test_sdbm.rb	(revision 41424)
+++ test/sdbm/test_sdbm.rb	(revision 41425)
@@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/sdbm/test_sdbm.rb#L1
 require 'test/unit'
 require 'tmpdir'
+require_relative '../ruby/envutil'
 
 begin
   require 'sdbm'
@@ -33,15 +34,6 @@ class TestSDBM < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/sdbm/test_sdbm.rb#L34
     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 https://github.com/ruby/ruby/blob/trunk/test/sdbm/test_sdbm.rb#L68
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]