From 397cf82c967e8ed106c98a0d6f54213f566c9c06 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 9 Sep 2014 17:51:25 -0700 Subject: [PATCH] depgraph: Walk finishes all non-dependent trees --- CHANGELOG.md | 1 + depgraph/graph.go | 11 ++--------- depgraph/graph_test.go | 8 ++++++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7018a13d4..7e2a15668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ BUG FIXES: * core: Providers are validated even without a `provider` block. [GH-284] + * core: In the case of error, walk all non-dependent trees. ## 0.2.2 (September 9, 2014) diff --git a/depgraph/graph.go b/depgraph/graph.go index ae3e51e6b..e4270206c 100644 --- a/depgraph/graph.go +++ b/depgraph/graph.go @@ -269,7 +269,6 @@ func (g *Graph) Walk(fn WalkFunc) error { // Spawn off all our goroutines to walk the tree errCh := make(chan error) - quitCh := make(chan struct{}) for len(tovisit) > 0 { // Grab the current thing to use n := len(tovisit) @@ -301,11 +300,8 @@ func (g *Graph) Walk(fn WalkFunc) error { ch := seenMap[dep.Target] seenMapL.RUnlock() - select { - case <-ch: - case <-quitCh: - return - } + // Wait for the dep to be run + <-ch // Check if any dependencies errored. If so, // then return right away, we won't walk it. @@ -343,9 +339,6 @@ func (g *Graph) Walk(fn WalkFunc) error { case <-doneCh: return nil case err := <-errCh: - // Close the quit channel so all our goroutines will end now - close(quitCh) - // Drain the error channel go func() { for _ = range errCh { diff --git a/depgraph/graph_test.go b/depgraph/graph_test.go index 6e38b885d..e00f6c543 100644 --- a/depgraph/graph_test.go +++ b/depgraph/graph_test.go @@ -389,7 +389,11 @@ c -> e`) func TestGraphWalk_error(t *testing.T) { nodes := ParseNouns(`a -> b b -> c -a -> d`) +a -> d +a -> e +e -> f +f -> g +g -> h`) list := NounMapToList(nodes) g := &Graph{Name: "Test", Nouns: list} if err := g.Validate(); err != nil { @@ -419,7 +423,7 @@ a -> d`) sort.Strings(walked) - expected := []string{"b", "c", "d"} + expected := []string{"b", "c", "d", "e", "f", "g", "h"} if !reflect.DeepEqual(walked, expected) { t.Fatalf("bad: %#v", walked) }