From c4d561646035b70d758c4745dd231a468e140132 Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:38:30 +0800 Subject: [PATCH 1/4] tests: Remove default_id_conv drb hack This doesn't seem needed any longer, especially since 2.2.3: https://github.com/ruby/drb/pull/35 --- spec/drb_default_id_conv.rb | 61 ------------------------------------- spec/drb_helper.rb | 2 -- spec/spec_helper.rb | 4 +-- 3 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 spec/drb_default_id_conv.rb diff --git a/spec/drb_default_id_conv.rb b/spec/drb_default_id_conv.rb deleted file mode 100644 index d30f897d..00000000 --- a/spec/drb_default_id_conv.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'drb' - -if defined?(JRUBY_VERSION) - require 'jruby' - - require 'weakref' - class DRb::WeakRefDRbIdConv - - def initialize - @id2ref = {} - end - - # Convert an object reference id to an object. - # - # This implementation looks up the reference id in the local object - # space and returns the object it refers to. - def to_obj(ref) - _get(ref) || super - end - - # Convert an object into a reference id. - # - # This implementation returns the object's __id__ in the local - # object space. - def to_id(obj) - (obj.nil? ? nil : _put(obj)) || super - end - - def _clean - dead = [] - @id2ref.each {|id,weakref| dead << id unless weakref.weakref_alive?} - dead.each {|id| @id2ref.delete(id)} - end - - def _put(obj) - _clean - @id2ref[obj.__id__] = WeakRef.new(obj) - obj.__id__ - end - - def _get(id) - weakref = @id2ref[id] - if weakref - result = weakref.__getobj__ rescue nil - if result - return result - else - @id2ref.delete id - end - end - nil - end - private :_clean, :_put, :_get - - end - - # NOTE: the same default object id converter #DRb::DRbIdConv as in 1.8 mode - # (not relying on ObjectSpace which is what #DRb::DRbIdConv does in 1.9) : - DRb::DRbServer.default_id_conv(DRb::WeakRefDRbIdConv.new) - -end diff --git a/spec/drb_helper.rb b/spec/drb_helper.rb index 5a48d930..e03cca92 100644 --- a/spec/drb_helper.rb +++ b/spec/drb_helper.rb @@ -50,8 +50,6 @@ def stop end end -require File.expand_path('drb_default_id_conv', File.dirname(__FILE__)) - server = WarblerDrbServer.new service = DRb.start_service 'druby://127.0.0.1:7890', server service.thread.join diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7f1f6c9c..3d415387 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,9 +37,6 @@ def capture(&block) io.string end -require 'drb' -require File.expand_path('drb_default_id_conv', File.dirname(__FILE__)) - module ExampleGroupHelpers def run_in_directory(dir) before :each do @@ -106,6 +103,7 @@ def create_git_gem(gem_name) def run_out_of_process_with_drb before :all do + require 'drb' DRb.start_service @orig_dir = Dir.pwd end From 7a061f3c7af7fb0398c4c589622b9d81ee750760 Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:42:07 +0800 Subject: [PATCH 2/4] tests: Cleanly shut down drb service Without this, you get nasty warnings like the below. warning: thread "Ruby-0-Thread-1: /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1584" terminated with exception (report_on_exception is true):warning: thread "Ruby-0-Thread-38: /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1584" terminated with exception (report_on_exception is true):IOError: closed stream select at org/jruby/RubyIO.java:3930 accept_or_shutdown at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1015 accept at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1001 main_loop at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1765 run at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1586 IOError: closed stream select at org/jruby/RubyIO.java:3930 accept_or_shutdown at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1015 accept at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1001 main_loop at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1765 run at /Users/chad/.local/share/mise/installs/ruby/jruby-9.4.14.0/lib/ruby/gems/shared/gems/drb-2.2.3/lib/drb/drb.rb:1586 --- spec/spec_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3d415387..d72f013f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -145,6 +145,10 @@ def run_out_of_process_with_drb drb.stop end end + + after :all do + DRb.stop_service + end end def use_test_webserver From 3bffe378f6791730330fb5fff73f905944b607a5 Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Tue, 28 Oct 2025 20:50:53 +0800 Subject: [PATCH 3/4] tests: Ensure child drb processes use the same drb version as bundled parent, not stdlib version Without this, tests break on JRuby 10 with errors such as `0x0000000000000fb4 is not id value` because `_idstr` is not used any longer. We want https://github.com/ruby/drb/pull/35 to be available, requiring 2.2.3 on both client and server. --- spec/drb_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/drb_helper.rb b/spec/drb_helper.rb index e03cca92..99ad7491 100644 --- a/spec/drb_helper.rb +++ b/spec/drb_helper.rb @@ -5,7 +5,9 @@ # See the file LICENSE.txt for details. #++ -require 'rubygems' +# Prefer gem version we already have on GEM_PATH from parent to ensure using the same version +# and avoid using outdated stdlib versions < 2.2.3 +gem 'drb' require 'drb' require 'stringio' require 'warbler' From aab3364d4d6194d7283db60626ec5c9d2b024d9a Mon Sep 17 00:00:00 2001 From: Chad Wilson <29788154+chadlwilson@users.noreply.github.com> Date: Tue, 28 Oct 2025 21:04:23 +0800 Subject: [PATCH 4/4] tests: Make drb specs a bit faster by using --dev on JRuby These are very short-lived processes, so optimisations aren't generally helpful. Shaves about 25% off bundler_spec.rb time (57s -> 46s) on a very quick machine. --- spec/spec_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d72f013f..82e3ad77 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -112,11 +112,11 @@ def run_out_of_process_with_drb drb DRbObject.new(nil, 'druby://127.0.0.1:7890').tap do |drbclient| ready, error = nil, nil - 300.times do # timeout 30 secs (300 * 0.1) + 600.times do # timeout 30 secs (600 * 0.05) begin break if ready = drbclient.ready? rescue DRb::DRbConnError => e - error = e; sleep 0.1 + error = e; sleep 0.05 end end raise error unless ready @@ -127,7 +127,7 @@ def run_out_of_process_with_drb require 'jruby' let(:drb) do drb_thread = Thread.new do - ruby "-I#{Warbler::WARBLER_HOME}/lib", File.join(@orig_dir, 'spec/drb_helper.rb') + ruby '--dev', "-I#{Warbler::WARBLER_HOME}/lib", File.join(@orig_dir, 'spec/drb_helper.rb') end drb_thread.run drb_thread