From 636648880971c1ed48da6518c87486d995f445d7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 3 Feb 2017 11:26:58 +0100 Subject: [PATCH] dag: Update can be called with a nil graph --- dag/walk.go | 5 ++++- dag/walk_test.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/dag/walk.go b/dag/walk.go index 826b7816e..72dad61de 100644 --- a/dag/walk.go +++ b/dag/walk.go @@ -136,7 +136,10 @@ func (w *Walker) Wait() error { // Multiple Updates can be called in parallel. Update can be called at any // time during a walk. func (w *Walker) Update(g *Graph) { - v, e := g.vertices, g.edges + var v, e *Set + if g != nil { + v, e = g.vertices, g.edges + } // Grab the change lock so no more updates happen but also so that // no new vertices are executed during this time since we may be diff --git a/dag/walk_test.go b/dag/walk_test.go index 04e6ebe3e..5843ca64b 100644 --- a/dag/walk_test.go +++ b/dag/walk_test.go @@ -33,6 +33,26 @@ func TestWalker_basic(t *testing.T) { } } +func TestWalker_updateNilGraph(t *testing.T) { + var g Graph + g.Add(1) + g.Add(2) + g.Connect(BasicEdge(1, 2)) + + // Run it a bunch of times since it is timing dependent + for i := 0; i < 50; i++ { + var order []interface{} + w := &Walker{Callback: walkCbRecord(&order)} + w.Update(&g) + w.Update(nil) + + // Wait + if err := w.Wait(); err != nil { + t.Fatalf("err: %s", err) + } + } +} + func TestWalker_error(t *testing.T) { var g Graph g.Add(1)