Remove sleep-based concurrency from newVertex test
Add a synchronization channel for the TestWalker_newVertex test, rather than using a sleep and running it multiple times.
This commit is contained in:
parent
2fce519f57
commit
0fb24c1a7a
|
@ -92,19 +92,33 @@ func TestWalker_error(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWalker_newVertex(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))
|
||||
|
||||
// Record function
|
||||
var order []interface{}
|
||||
w := &Walker{Callback: walkCbRecord(&order)}
|
||||
recordF := walkCbRecord(&order)
|
||||
done2 := make(chan int)
|
||||
|
||||
// Build a callback that notifies us when 2 has been walked
|
||||
var w *Walker
|
||||
cb := func(v Vertex) error {
|
||||
if v == 2 {
|
||||
defer func() {
|
||||
close(done2)
|
||||
}()
|
||||
}
|
||||
return recordF(v)
|
||||
}
|
||||
|
||||
// Add the initial vertices
|
||||
w = &Walker{Callback: cb}
|
||||
w.Update(&g)
|
||||
|
||||
// Wait a bit
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
// if 2 has been visited, the walk is complete so far
|
||||
<-done2
|
||||
|
||||
// Update the graph
|
||||
g.Add(3)
|
||||
|
@ -124,7 +138,6 @@ func TestWalker_newVertex(t *testing.T) {
|
|||
if !reflect.DeepEqual(order, expected) {
|
||||
t.Fatalf("bad: %#v", order)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWalker_removeVertex(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue