diff --git a/lib/sshkit/runners/group.rb b/lib/sshkit/runners/group.rb index eaf9680c..54e4bbee 100644 --- a/lib/sshkit/runners/group.rb +++ b/lib/sshkit/runners/group.rb @@ -11,9 +11,10 @@ def initialize(hosts, options = nil, &block) end def execute - hosts.each_slice(group_size).collect do |group_hosts| + last_group_index = (hosts.length - 1) / group_size + hosts.each_slice(group_size).with_index.collect do |group_hosts, index| Parallel.new(group_hosts, &block).execute - sleep wait_interval + sleep wait_interval unless index == last_group_index end.flatten end diff --git a/test/unit/runners/test_group.rb b/test/unit/runners/test_group.rb index eb740e08..75679992 100644 --- a/test/unit/runners/test_group.rb +++ b/test/unit/runners/test_group.rb @@ -12,6 +12,15 @@ def test_wraps_ruby_standard_error_in_execute_error end assert_match(/while executing.*localhost/, error.message) end + + def test_waits_only_between_groups + hosts = Array.new(5) { Host.new(:local) } + runner = Group.new(hosts, limit: 2, wait: 3) {} + Parallel.any_instance.stubs(:execute).returns([]) + runner.expects(:sleep).with(3).twice + + assert_equal [nil, nil, nil], runner.execute + end end end end