diff --git a/dag/walk_test.go b/dag/walk_test.go index ca33e1097..6c1f24942 100644 --- a/dag/walk_test.go +++ b/dag/walk_test.go @@ -175,43 +175,42 @@ func TestWalker_removeVertex(t *testing.T) { } func TestWalker_newEdge(t *testing.T) { - // Run it a bunch of times since it is timing dependent - for i := 0; i < 50; i++ { - var g AcyclicGraph - g.Add(1) - g.Add(2) - g.Connect(BasicEdge(1, 2)) + var g AcyclicGraph + g.Add(1) + g.Add(2) + g.Connect(BasicEdge(1, 2)) - // Record function - var order []interface{} - recordF := walkCbRecord(&order) + // Record function + var order []interface{} + recordF := walkCbRecord(&order) - // Build a callback that delays until we close a channel - var w *Walker - cb := func(v Vertex) error { - if v == 1 { - g.Add(3) - g.Connect(BasicEdge(3, 2)) - w.Update(&g) - } + var w *Walker + cb := func(v Vertex) error { + // record where we are first, otherwise the Updated vertex may get + // walked before the first visit. + err := recordF(v) - return recordF(v) + if v == 1 { + g.Add(3) + g.Connect(BasicEdge(3, 2)) + w.Update(&g) } + return err + } - // Add the initial vertices - w = &Walker{Callback: cb} - w.Update(&g) + // Add the initial vertices + w = &Walker{Callback: cb} + w.Update(&g) - // Wait - if err := w.Wait(); err != nil { - t.Fatalf("err: %s", err) - } + // Wait + if err := w.Wait(); err != nil { + t.Fatalf("err: %s", err) + } - // Check - expected := []interface{}{1, 3, 2} - if !reflect.DeepEqual(order, expected) { - t.Fatalf("bad: %#v", order) - } + // Check + expected := []interface{}{1, 3, 2} + if !reflect.DeepEqual(order, expected) { + t.Fatalf("bad: %#v", order) } }