Fix parallel command execution logging parallely - GH434

Also add unit tests that reproduce the problem
This commit is contained in:
Hemant Kumar 2013-04-25 14:03:44 +05:30
parent c4bd4c4e03
commit a08fe0d67d
4 changed files with 48 additions and 8 deletions

View File

@ -9,4 +9,5 @@ gemspec
#
group :development do
gem "rake"
gem "pry"
end

View File

@ -163,10 +163,11 @@ module Capistrano
if tree.branches.any? || tree.fallback
_, servers = filter_servers(options)
branches = servers.map{|server| tree.branches_for(server)}.compact
branches = branches_for_servers(tree,servers)
case branches.size
when 0
branches = tree.branches.dup + [tree.fallback]
branches.compact!
case branches.size
when 1
logger.debug "no servers for #{branches.first}"
@ -178,13 +179,7 @@ module Capistrano
logger.debug "executing #{branches.first}" unless options[:silent]
else
logger.debug "executing multiple commands in parallel"
branches.each {|maybe_branch|
if(maybe_branch.is_a?(Array))
maybe_branch.each {|branch| logger.trace "-> #{branch.to_s(true)}"}
else
logger.trace "-> #{maybe_branch.to_s(true)}"
end
}
branches.each {|branch| logger.trace "-> #{branch.to_s(true)}" }
end
else
raise ArgumentError, "attempt to execute without specifying a command"
@ -317,6 +312,17 @@ module Capistrano
exit(-1)
end
end
private
def branches_for_servers(tree,servers)
servers.inject([]) do |branches,server|
if server_branches = tree.branches_for(server)
branches += server_branches
end
branches
end
end
end
end
end

View File

@ -9,6 +9,7 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
attr_accessor :dry_run
attr_accessor :preserve_roles
attr_accessor :servers
attr_accessor :roles
def initialize
@options = {}
@ -226,6 +227,37 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
@config.invoke_command("ls", :once => true, :via => :foobar)
end
def test_parallel_command_execution_with_no_match
assert_block("should not raise argument error") do
begin
@config.parallel do |session|
session.when("in?(:app)", "ls") {|ch,stream,data| puts "noop"}
session.when("in?(:db)", "pwd") {|ch,stream,data| puts "noop"}
end
true
rescue
false
end
end
end
def test_parallel_command_execution_with_matching_servers
@config.expects(:execute_on_servers)
assert_block("should not raise Argument error") do
begin
@config.servers = [:app, :db]
@config.roles = {:app => [:app], :db => [:db] }
@config.parallel do |session|
session.when("in?(:app)", "ls") {|ch,stream,data| puts "noop"}
session.when("in?(:db)", "pwd") {|ch,stream,data| puts "noop"}
end
true
rescue
false
end
end
end
private
def make_config

View File

@ -5,6 +5,7 @@ require 'test/unit'
require 'mocha'
require 'capistrano/server_definition'
require 'pry'
module TestExtensions
def server(host, options={})