dag: Update can be called with a nil graph

This commit is contained in:
Mitchell Hashimoto 2017-02-03 11:26:58 +01:00
parent 65752cd51a
commit 6366488809
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 24 additions and 1 deletions

View File

@ -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

View File

@ -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)