Ruby 启动DRb服务,然后分叉并通过服务进行通信-为什么';这不管用吗?
我想创建一个Ruby 启动DRb服务,然后分叉并通过服务进行通信-为什么';这不管用吗?,ruby,Ruby,我想创建一个隔离用于隔离测试中全局状态更改的测试方法。我们使用Minitest作为测试套件。我目前的方法是使用当前的minitest报告器fork启动DRb,然后通过DRb将结果传递回主流程 这就是我现在拥有的: module ForkingRunner require 'drb' def run(reporter, options = {}) with_drb_reporter(reporter) do |_reporter| super _reporter, o
隔离代码>用于隔离测试中全局状态更改的测试方法。我们使用Minitest作为测试套件。我目前的方法是使用当前的minitest报告器fork启动DRb,然后通过DRb将结果传递回主流程
这就是我现在拥有的:
module ForkingRunner
require 'drb'
def run(reporter, options = {})
with_drb_reporter(reporter) do |_reporter|
super _reporter, options
puts _reporter.reporters.first.count
end
end
private
def drb_path
"drbunix:#{Rails.root.join('tmp/minitest-fork')}"
end
def with_drb_reporter(reporter)
DRb.start_service drb_path, reporter
pid = fork do
yield DRbObject.new_with_uri(drb_path)
end
Process.wait pid
puts reporter.reporters.first.count
ensure
DRb.stop_service
end
end
ActiveSupport::TestCase.class_eval do
def self.isolate!
singleton_class.prepend ForkingRunner
end
end
请注意,在我的分支进程中的run
中的super
之后,报告程序的测试计数是有效的,但是在分支返回并使用_drb_reporter
后,从我的主进程查询报告程序时,报告程序的测试计数仍然是0
你知道为什么这样不行吗?我对DRb还比较陌生,所以这可能有点怪。这和我的DRb连接搞砸了有关吗