lib/tork/master.rb in tork-16.0.0 vs lib/tork/master.rb in tork-17.0.0
- old
+ new
@@ -1,6 +1,5 @@
-require 'json'
require 'tork/server'
require 'tork/config'
module Tork
module Master
@@ -15,22 +14,22 @@
branch, leaf = File.split(file)
file = leaf if paths.include? branch
require file.sub(/\.rb$/, '')
end
- @client.print @command_line
+ @client.send @command
end
def test test_file, line_numbers
# throttle forking rate to meet the maximum concurrent workers limit
sleep 1 until @command_by_worker_pid.size < Config.max_forked_workers
log_file = test_file + '.log'
worker_number = @worker_number_pool.shift
Config.before_fork_hooks.each do |hook|
- hook.call worker_number, log_file, test_file, line_numbers
+ hook.call test_file, line_numbers, log_file, worker_number
end
worker_pid = fork do
# make the process title Test::Unit friendly and ps(1) searchable
$0 = "tork-worker[#{worker_number}] #{test_file}"
@@ -44,22 +43,22 @@
# capture test output in log file because tests are run in parallel
# which makes it difficult to understand interleaved output thereof
STDERR.reopen(STDOUT.reopen(log_file, 'w')).sync = true
Config.after_fork_hooks.each do |hook|
- hook.call worker_number, log_file, test_file, line_numbers
+ hook.call test_file, line_numbers, log_file, worker_number
end
# after loading the user's test file, the at_exit() hook of the user's
# testing framework will take care of running the tests and reflecting
# any failures in the worker process' exit status, which will then be
# handled by the SIGCHLD trap registered in the master process (below)
Kernel.load test_file
end
- @command_by_worker_pid[worker_pid] = @command.push(worker_number)
- @client.print @command_line
+ @command_by_worker_pid[worker_pid] = @command.push(log_file, worker_number)
+ @client.send @command
end
def stop
# NOTE: the SIGCHLD handler will reap these killed worker processes
Process.kill :SIGTERM, *@command_by_worker_pid.keys.map {|pid| -pid }
@@ -81,12 +80,12 @@
trap :SIGCHLD do
begin
while wait2_array = Process.wait2(-1, Process::WNOHANG)
child_pid, child_status = wait2_array
if command = @command_by_worker_pid.delete(child_pid)
- @worker_number_pool.push command.pop
- command[0] = child_status.success? ? 'pass' : 'fail'
- @client.puts JSON.dump(command.push(child_status))
+ @worker_number_pool.push command.last
+ command[0] = if child_status.success? then :pass else :fail end
+ @client.send command.push(child_status)
else
warn "tork-master: unknown child exited: #{wait2_array.inspect}"
end
end
rescue SystemCallError