Sha256: 8c4a9a1efbd6105a407bfa82f4479ce4648e10dd65d87fa0ec603d615846332a

Contents?: true

Size: 1.2 KB

Versions: 90

Compression:

Stored size: 1.2 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 size
        @worker_count
      end

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

Version data entries

90 entries across 86 versions & 12 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/testing/parallelization.rb
activesupport-8.0.1 lib/active_support/testing/parallelization.rb
activesupport-8.0.0.1 lib/active_support/testing/parallelization.rb
activesupport-7.2.2.1 lib/active_support/testing/parallelization.rb
activesupport-7.1.5.1 lib/active_support/testing/parallelization.rb
activesupport-7.0.8.7 lib/active_support/testing/parallelization.rb
activesupport-8.0.0 lib/active_support/testing/parallelization.rb
activesupport-7.2.2 lib/active_support/testing/parallelization.rb
activesupport-7.1.5 lib/active_support/testing/parallelization.rb
activesupport-8.0.0.rc2 lib/active_support/testing/parallelization.rb
activesupport-7.2.1.2 lib/active_support/testing/parallelization.rb
activesupport-7.1.4.2 lib/active_support/testing/parallelization.rb
activesupport-7.0.8.6 lib/active_support/testing/parallelization.rb
activesupport-8.0.0.rc1 lib/active_support/testing/parallelization.rb
activesupport-7.2.1.1 lib/active_support/testing/parallelization.rb
activesupport-7.1.4.1 lib/active_support/testing/parallelization.rb
activesupport-7.0.8.5 lib/active_support/testing/parallelization.rb
activesupport-8.0.0.beta1 lib/active_support/testing/parallelization.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/testing/parallelization.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/testing/parallelization.rb