Sha256: 3e11b117a334903e5493a48eb9fe98e5b42fc0a073abe8b9bc08eed5b08a3c35

Contents?: true

Size: 1.16 KB

Versions: 42

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "drb"
require "drb/unix" unless Gem.win_platform?
require "active_support/core_ext/module/attribute_accessors"
require "active_support/testing/parallelization/server"
require "active_support/testing/parallelization/worker"

module ActiveSupport
  module Testing
    class Parallelization # :nodoc:
      @@after_fork_hooks = []

      def self.after_fork_hook(&blk)
        @@after_fork_hooks << blk
      end

      cattr_reader :after_fork_hooks

      @@run_cleanup_hooks = []

      def self.run_cleanup_hook(&blk)
        @@run_cleanup_hooks << blk
      end

      cattr_reader :run_cleanup_hooks

      def initialize(worker_count)
        @worker_count = worker_count
        @queue_server = Server.new
        @worker_pool = []
        @url = DRb.start_service("drbunix:", @queue_server).uri
      end

      def start
        @worker_pool = @worker_count.times.map do |worker|
          Worker.new(worker, @url).start
        end
      end

      def <<(work)
        @queue_server << work
      end

      def shutdown
        @queue_server.shutdown
        @worker_pool.each { |pid| Process.waitpid pid }
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 7 rubygems

Version Path
activesupport-6.1.7.10 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.9 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.8 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.7 lib/active_support/testing/parallelization.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activesupport-6.1.6.1/lib/active_support/testing/parallelization.rb
activesupport-6.1.7.6 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.5 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.4 lib/active_support/testing/parallelization.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activesupport-6.1.6.1/lib/active_support/testing/parallelization.rb
activesupport-6.1.7.3 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.2 lib/active_support/testing/parallelization.rb
activesupport-6.1.7.1 lib/active_support/testing/parallelization.rb
activesupport-6.1.7 lib/active_support/testing/parallelization.rb
activesupport-6.1.6.1 lib/active_support/testing/parallelization.rb
activesupport-6.1.6 lib/active_support/testing/parallelization.rb
activesupport-6.1.5.1 lib/active_support/testing/parallelization.rb
activesupport-6.1.5 lib/active_support/testing/parallelization.rb
activesupport-6.1.4.7 lib/active_support/testing/parallelization.rb
activesupport-6.1.4.6 lib/active_support/testing/parallelization.rb
activesupport-6.1.4.5 lib/active_support/testing/parallelization.rb