diff --git a/Gemfile b/Gemfile index 16829b07..2bd74570 100644 --- a/Gemfile +++ b/Gemfile @@ -9,4 +9,5 @@ gemspec # group :development do gem "rake" + gem "pry" end diff --git a/lib/capistrano/configuration/actions/invocation.rb b/lib/capistrano/configuration/actions/invocation.rb index ab192b55..f43e7ebf 100644 --- a/lib/capistrano/configuration/actions/invocation.rb +++ b/lib/capistrano/configuration/actions/invocation.rb @@ -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 diff --git a/test/configuration/actions/invocation_test.rb b/test/configuration/actions/invocation_test.rb index fb0c91da..b019f754 100644 --- a/test/configuration/actions/invocation_test.rb +++ b/test/configuration/actions/invocation_test.rb @@ -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 diff --git a/test/utils.rb b/test/utils.rb index da8821fb..a151f843 100644 --- a/test/utils.rb +++ b/test/utils.rb @@ -5,6 +5,7 @@ require 'test/unit' require 'mocha' require 'capistrano/server_definition' +require 'pry' module TestExtensions def server(host, options={})