Spork::RunStrategy::Magazine

Constants

Slave_Id_Range

Public Class Methods

available?() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 72
def self.available?
  true
end
new(test_framework) click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 28
def initialize(test_framework)
  @test_framework = test_framework
  this_path = File.expand_path(File.dirname(__FILE__))
  @path = File.join(this_path, 'magazine')
  @pids = []

  @pids << start_Rinda_ringserver
  sleep 1

  fill_slave_pool
rescue RuntimeError => e
  kill_all_processes
  raise e
end

Public Instance Methods

abort() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 116
def abort
  kill_all_processes
end
fill_slave_pool() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 48
def fill_slave_pool
  Slave_Id_Range.each do |id|
    start_slave(id)
  end
  puts "  -- Starting to fill pool..."
  puts "     Wait until at least one slave is provided before running tests..."
  puts "  ** CTRL+BREAK to stop Spork and kill all ruby slave processes **"
  $stdout.flush
end
kill_all_processes() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 103
def kill_all_processes

  @pids.each {|pid| Process.kill(9, pid)}
  puts "\nKilling processes."; $stdout.flush
end
preload() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 120
def preload
  true
  #    @test_framework.preload
end
restart_slave(id) click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 97
def restart_slave(id)
  pid   = @pids[id]
  Process.kill(9, pid)
  start_slave(id)
end
run(argv, stderr, stdout) click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 76
def run(argv, stderr, stdout)
      DRb.start_service
      ts = Rinda::RingFinger.primary
      if ts.read_all([:name, :MagazineSlave, nil, nil]).size > 0
        print '  <-- take tuple'; stdout.flush
        tuple = ts.take([:name, :MagazineSlave, nil, nil])
        slave = tuple[2]
        id = tuple[3]

        puts "(#{slave.id_num}); slave.run..."; $stdout.flush
        begin
          slave.run(argv,stderr,stdout)
          puts "   -- (#{slave.id_num});run done"; $stdout.flush
        ensure
          restart_slave(id)
        end
      else
        puts '- NO tuple'; $stdout.flush
      end
end
running?() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 125
def running?
  @running
end
slave_count() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 109
def slave_count
  DRb.start_service
  ts = Rinda::RingFinger.primary
  ts.read_all([:name, :MagazineSlave, nil, nil]).size
end
slave_max() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 24
def slave_max
  Slave_Id_Range.to_a.size
end
spawn_process(app) click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 64
def spawn_process(app)
  if RUBY_VERSION < '1.9.1'
    Process.create( :app_name => app, :cwd => @path ).process_id
  else
    Process.spawn( app, :chdir => @path )
  end
end
start_Rinda_ringserver() click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 43
def start_Rinda_ringserver
  app_name = 'ruby ring_server.rb'
  spawn_process(app_name)    
end
start_slave(id) click to toggle source
# File lib/spork/run_strategy/magazine.rb, line 58
def start_slave(id)
  app_pwd = Dir.pwd  # path running app in
  app = "ruby magazine_slave_provider.rb #{id} '#{app_pwd}' #{@test_framework.short_name}"
  @pids[id] = spawn_process(app)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.