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
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.4/lib/active_support/testing/parallelization.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.4/lib/active_support/testing/parallelization.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/activesupport-6.1.4.4/lib/active_support/testing/parallelization.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.4.4/lib/active_support/testing/parallelization.rb
activesupport-6.1.4.4 lib/active_support/testing/parallelization.rb
activesupport-6.1.4.3 lib/active_support/testing/parallelization.rb
activesupport-6.1.4.2 lib/active_support/testing/parallelization.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.4.1/lib/active_support/testing/parallelization.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.4.1/lib/active_support/testing/parallelization.rb
activesupport-6.1.4.1 lib/active_support/testing/parallelization.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.4/lib/active_support/testing/parallelization.rb
activesupport-6.1.4 lib/active_support/testing/parallelization.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3.1/lib/active_support/testing/parallelization.rb
activesupport-6.1.3.2 lib/active_support/testing/parallelization.rb
activesupport-6.1.3.1 lib/active_support/testing/parallelization.rb
activesupport-6.1.3 lib/active_support/testing/parallelization.rb
activesupport-6.1.2.1 lib/active_support/testing/parallelization.rb
activesupport-6.1.2 lib/active_support/testing/parallelization.rb
activesupport-6.1.1 lib/active_support/testing/parallelization.rb
activesupport-6.1.0 lib/active_support/testing/parallelization.rb