Remove loop from TestWalker_removeVertex

There's no timing dependent behavior here, since V1 must be visited
before V2, Remove and Update must be called before V2 is visited.
This commit is contained in:
James Bardin 2017-02-20 15:07:09 -05:00
parent 0fb24c1a7a
commit 7bf33c2a7f

View File

@ -106,9 +106,7 @@ func TestWalker_newVertex(t *testing.T) {
var w *Walker
cb := func(v Vertex) error {
if v == 2 {
defer func() {
close(done2)
}()
defer close(done2)
}
return recordF(v)
}
@ -141,42 +139,38 @@ func TestWalker_newVertex(t *testing.T) {
}
func TestWalker_removeVertex(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.Remove(2)
w.Update(&g)
}
return recordF(v)
var w *Walker
cb := func(v Vertex) error {
if v == 1 {
g.Remove(2)
w.Update(&g)
}
// Add the initial vertices
w = &Walker{Callback: cb}
w.Update(&g)
return recordF(v)
}
// Wait
if err := w.Wait(); err != nil {
t.Fatalf("err: %s", err)
}
// Add the initial vertices
w = &Walker{Callback: cb}
w.Update(&g)
// Check
expected := []interface{}{1}
if !reflect.DeepEqual(order, expected) {
t.Fatalf("bad: %#v", order)
}
// Wait
if err := w.Wait(); err != nil {
t.Fatalf("err: %s", err)
}
// Check
expected := []interface{}{1}
if !reflect.DeepEqual(order, expected) {
t.Fatalf("bad: %#v", order)
}
}