Class: ActiveSupport::Testing::Parallelization

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/testing/parallelization.rb,
lib/active_support/testing/parallelization/server.rb,
lib/active_support/testing/parallelization/worker.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Server, Worker

Constant Summary collapse

@@after_fork_hooks =
[]
@@run_cleanup_hooks =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker_count) ⇒ Parallelization

Returns a new instance of Parallelization.



28
29
30
31
32
33
# File 'lib/active_support/testing/parallelization.rb', line 28

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

Class Method Details

.after_fork_hook(&blk) ⇒ Object



14
15
16
# File 'lib/active_support/testing/parallelization.rb', line 14

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

.run_cleanup_hook(&blk) ⇒ Object



22
23
24
# File 'lib/active_support/testing/parallelization.rb', line 22

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

Instance Method Details

#<<(work) ⇒ Object



41
42
43
# File 'lib/active_support/testing/parallelization.rb', line 41

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

#shutdownObject



45
46
47
48
# File 'lib/active_support/testing/parallelization.rb', line 45

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

#startObject



35
36
37
38
39
# File 'lib/active_support/testing/parallelization.rb', line 35

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