Class: Spork::RunStrategy::Magazine
- Inherits:
-
Spork::RunStrategy
- Object
- Spork::RunStrategy
- Spork::RunStrategy::Magazine
- Defined in:
- lib/spork/run_strategy/magazine.rb
Constant Summary collapse
- Slave_Id_Range =
Ringserver uses id: 0. Slave use: 1..MAX_SLAVES
1..2
Instance Attribute Summary
Attributes inherited from Spork::RunStrategy
Class Method Summary collapse
Instance Method Summary collapse
- #abort ⇒ Object
- #fill_slave_pool ⇒ Object
-
#initialize(test_framework) ⇒ Magazine
constructor
A new instance of Magazine.
- #kill_all_processes ⇒ Object
- #preload ⇒ Object
- #restart_slave(id) ⇒ Object
- #run(argv, stderr, stdout) ⇒ Object
- #running? ⇒ Boolean
- #slave_count ⇒ Object
- #slave_max ⇒ Object
- #start_Rinda_ringserver ⇒ Object
- #start_slave(id) ⇒ Object
Methods inherited from Spork::RunStrategy
Constructor Details
#initialize(test_framework) ⇒ Magazine
Returns a new instance of Magazine.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/spork/run_strategy/magazine.rb', line 20 def initialize(test_framework) @test_framework = test_framework this_path = File.(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 |
Class Method Details
.available? ⇒ Boolean
57 58 59 |
# File 'lib/spork/run_strategy/magazine.rb', line 57 def self.available? true end |
Instance Method Details
#abort ⇒ Object
101 102 103 |
# File 'lib/spork/run_strategy/magazine.rb', line 101 def abort kill_all_processes end |
#fill_slave_pool ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/spork/run_strategy/magazine.rb', line 40 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 ⇒ Object
88 89 90 91 92 |
# File 'lib/spork/run_strategy/magazine.rb', line 88 def kill_all_processes @pids.each {|pid| Process.kill(4, pid)} puts "\nKilling processes."; $stdout.flush end |
#preload ⇒ Object
105 106 107 108 |
# File 'lib/spork/run_strategy/magazine.rb', line 105 def preload true # @test_framework.preload end |
#restart_slave(id) ⇒ Object
82 83 84 85 86 |
# File 'lib/spork/run_strategy/magazine.rb', line 82 def restart_slave(id) pid = @pids[id] Process.kill(4, pid) start_slave(id) end |
#run(argv, stderr, stdout) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/spork/run_strategy/magazine.rb', line 61 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? ⇒ Boolean
110 111 112 |
# File 'lib/spork/run_strategy/magazine.rb', line 110 def running? @running end |
#slave_count ⇒ Object
94 95 96 97 98 |
# File 'lib/spork/run_strategy/magazine.rb', line 94 def slave_count DRb.start_service ts = Rinda::RingFinger.primary ts.read_all([:name, :MagazineSlave, nil, nil]).size end |
#slave_max ⇒ Object
16 17 18 |
# File 'lib/spork/run_strategy/magazine.rb', line 16 def slave_max Slave_Id_Range.to_a.size end |
#start_Rinda_ringserver ⇒ Object
35 36 37 38 |
# File 'lib/spork/run_strategy/magazine.rb', line 35 def start_Rinda_ringserver app_name = 'ruby ring_server.rb' Process.create( :app_name => app_name, :cwd => @path ).process_id end |
#start_slave(id) ⇒ Object
50 51 52 53 54 |
# File 'lib/spork/run_strategy/magazine.rb', line 50 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] = Process.create( :app_name => app, :cwd => @path ).process_id end |