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

ruby-changes:43794

From: nagachika <ko1@a...>
Date: Fri, 12 Aug 2016 03:30:24 +0900 (JST)
Subject: [ruby-changes:43794] nagachika:r55867 (ruby_2_3): merge revision(s) 55008: [Backport #12342]

nagachika	2016-08-12 03:30:09 +0900 (Fri, 12 Aug 2016)

  New Revision: 55867

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55867

  Log:
    merge revision(s) 55008: [Backport #12342]
    
    * lib/drb/timeridconv.rb: don't use keeper thread. [Bug #12342]
    
    * test/drb/ut_timerholder.rb: ditto.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/lib/drb/timeridconv.rb
    branches/ruby_2_3/test/drb/ut_timerholder.rb
    branches/ruby_2_3/version.h
Index: ruby_2_3/lib/drb/timeridconv.rb
===================================================================
--- ruby_2_3/lib/drb/timeridconv.rb	(revision 55866)
+++ ruby_2_3/lib/drb/timeridconv.rb	(revision 55867)
@@ -18,26 +18,27 @@ module DRb https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/drb/timeridconv.rb#L18
 
       class InvalidIndexError < RuntimeError; end
 
-      def initialize(timeout=600)
+      def initialize(keeping=600)
         super()
         @sentinel = Object.new
         @gc = {}
-        @curr = {}
         @renew = {}
-        @timeout = timeout
-        @keeper = keeper
+        @keeping = keeping
+        @expires = Time.now + @keeping
       end
 
       def add(obj)
         synchronize do
+          rotate
           key = obj.__id__
-          @curr[key] = obj
+          @renew[key] = obj
           return key
         end
       end
 
       def fetch(key, dv=@sentinel)
         synchronize do
+          rotate
           obj = peek(key)
           if obj == @sentinel
             return dv unless dv == @sentinel
@@ -48,42 +49,35 @@ module DRb https://github.com/ruby/ruby/blob/trunk/ruby_2_3/lib/drb/timeridconv.rb#L49
         end
       end
 
-      def include?(key)
-        synchronize do
-          obj = peek(key)
-          return false if obj == @sentinel
-          true
-        end
-      end
-
+      private
       def peek(key)
         synchronize do
-          return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
+          return @renew.fetch(key) { @gc.fetch(key, @sentinel) }
         end
       end
 
-      private
-      def alternate
+      def rotate
         synchronize do
-          @gc = @curr       # GCed
-          @curr = @renew
+          return if @expires > Time.now
+          @gc = @renew      # GCed
           @renew = {}
+          @expires = Time.now + @keeping
         end
       end
 
       def keeper
         Thread.new do
           loop do
-            alternate
-            sleep(@timeout)
+            rotate
+            sleep(@keeping)
           end
         end
       end
     end
 
-    # Creates a new TimerIdConv which will hold objects for +timeout+ seconds.
-    def initialize(timeout=600)
-      @holder = TimerHolder2.new(timeout)
+    # Creates a new TimerIdConv which will hold objects for +keeping+ seconds.
+    def initialize(keeping=600)
+      @holder = TimerHolder2.new(keeping)
     end
 
     def to_obj(ref) # :nodoc:
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 55866)
+++ ruby_2_3/version.h	(revision 55867)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.2"
 #define RUBY_RELEASE_DATE "2016-08-12"
-#define RUBY_PATCHLEVEL 147
+#define RUBY_PATCHLEVEL 148
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 8
Index: ruby_2_3/test/drb/ut_timerholder.rb
===================================================================
--- ruby_2_3/test/drb/ut_timerholder.rb	(revision 55866)
+++ ruby_2_3/test/drb/ut_timerholder.rb	(revision 55867)
@@ -1,54 +1,38 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/drb/ut_timerholder.rb#L1
 # frozen_string_literal: false
-require 'runit/testcase'
-require 'runit/cui/testrunner'
-require 'timerholder'
+require 'test/unit'
+require 'drb/timeridconv'
 
 module DRbTests
 
-class TimerHolderTest < RUNIT::TestCase
-  def do_test(timeout, keeper_sleep = nil)
-    holder = TimerHolder.new(timeout)
-    holder.keeper_sleep = keeper_sleep if keeper_sleep
-    key = holder.add(self)
-    sleep(timeout * 0.5)
-    assert_equal(holder.peek(key), self)
-    holder.delete(key)
-    assert(!holder.include?(key))
-    key = holder.add(self)
-    sleep(timeout+0.5)
-    assert_equal(holder.fetch(key), nil)
-    key = holder.add(self)
-    assert_equal(holder.fetch(key), self)
-    holder.store(key, true)
-    assert_equal(holder.fetch(key), true)
-    assert_equal(holder.include?(key), true)
-    sleep(timeout+0.5)
-    assert_exception(TimerHolder::InvalidIndexError) do
-      holder.store(key, 1)
-    end
-    assert_equal(holder.include?(key), false)
-    key = holder.add(self)
-    sleep(timeout * 0.5)
-    assert(holder.include?(key))
-    holder.extend(key, timeout)
-    sleep(timeout * 0.5)
-    assert(holder.include?(key))
-    sleep(timeout * 0.6)
-    assert(!holder.include?(key))
-    holder.delete(key)
-  end
+class TimerIdConvTest < Test::Unit::TestCase
+  def test_usecase_01
+    keeping = 0.1
+    idconv = DRb::TimerIdConv.new(keeping)
+
+    key = idconv.to_id(self)
+    assert_equal(key, self.__id__)
+    sleep(keeping)
+
+    assert_equal(idconv.to_id(false), false.__id__)
+    assert_equal(idconv.to_obj(key), self)
+    sleep(keeping)
 
-  def test_00
-    do_test(0.5)
-  end
+    assert_equal(idconv.to_obj(key), self)
+    sleep(keeping)
 
-  def test_01
-    do_test(1, 0.5)
+    assert_equal(idconv.to_id(true), true.__id__)
+    sleep(keeping)
+
+    assert_raise do
+      assert_equal(idconv.to_obj(key))
+    end
+
+    assert_raise do
+      assert_equal(idconv.to_obj(false.__id__))
+    end
   end
 end
 
-end
 
-if __FILE__ == $0
-  RUNIT::CUI::TestRunner.run(DRbTests::TimerHolderTest.suite)
 end
+
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 55866)
+++ ruby_2_3/ChangeLog	(revision 55867)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Fri Aug 12 03:00:05 2016  Masatoshi SEKI  <m_seki@m...>
+
+	* lib/drb/timeridconv.rb: don't use keeper thread. [Bug #12342]
+
+	* test/drb/ut_timerholder.rb: ditto.
+
 Fri Aug 12 02:46:37 2016  Kazuki Yamaguchi  <k@r...>
 
 	* ext/openssl/ossl_ssl.c (ossl_ssl_stop): Don't free the SSL struct

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r55008


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

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