Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't blow the stack on recursive dependencies.

  • Loading branch information...
commit 985d70df0e1615d38ce19beef906d8cfd59eb7ce 1 parent 64d4da2
@threedaymonk threedaymonk authored
View
6 lib/bowler/dependency_tree.rb
@@ -13,9 +13,11 @@ def initialize(definition)
@definition = definition
end
- def dependencies_for(processes)
+ def dependencies_for(processes, visited = [])
return [] unless processes
- processes.map { |p| [dependencies_for(@definition.tree[p]), p] }.flatten.compact.uniq
+ (processes - visited).map { |p|
+ [dependencies_for(@definition.tree[p], visited + [p]), p]
+ }.flatten.compact.uniq
end
def process_list_for(processes)
View
6 spec/dependency_tree_spec.rb
@@ -21,6 +21,12 @@ module Bowler
tree.dependencies_for([:cat]).should =~ [:cat, :nyan, :bar, :foo, :required]
end
+
+ it "should correctly handle recursive dependencies" do
+ tree = DependencyTree.load File.join( File.dirname(__FILE__), 'fixtures', 'dependency_tree_pinfile' )
+
+ tree.dependencies_for([:loop1]).should =~ [:loop1, :loop2, :required]
+ end
end
context "given an array of one process" do
View
2  spec/fixtures/dependency_tree_pinfile
@@ -3,4 +3,6 @@ dependency :required
process :foo => :bar
process :nyan => [:foo, :bar]
process :cat => :nyan
+process :loop1 => :loop2
+process :loop2 => :loop1
process :rick
Please sign in to comment.
Something went wrong with that request. Please try again.