mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-12 09:01:58 -06:00
Remove intermittent failure from newEdge test
Because the vertex visit was record after the Update call, Updated vertices may have been visited before the visit was recorded, causing occasional test failures. The order is now deterministic, and we can remove the brute-force loop.
This commit is contained in:
parent
7bf33c2a7f
commit
d01b0b0647
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user