From 0255db5120f33c013bdaeeb600973280e1e0aaeb Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 10 Dec 2018 14:56:54 +0100 Subject: [PATCH] autopilot/prefattach_test: ensure non-connected nodes get 0-score This addition to the unit tests makes sure nodes that have no channels in the graph are left out od the scored nodes, implicitly giving them a score of 0. --- autopilot/prefattach_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go index 5801c00d..f485ce7d 100644 --- a/autopilot/prefattach_test.go +++ b/autopilot/prefattach_test.go @@ -376,6 +376,12 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) { t1.Fatalf("unable to generate channel: %v", err) } + // We also add a third, non-connected node to the graph. + _, err = graph.addRandNode() + if err != nil { + t1.Fatalf("unable to add random node: %v", err) + } + // Get the score for all nodes found in the graph at // this point. nodes := make(map[NodeID]struct{}) @@ -386,7 +392,7 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) { t1.Fatalf("unable to traverse graph: %v", err) } - if len(nodes) != 2 { + if len(nodes) != 3 { t1.Fatalf("expected 2 nodes, found %d", len(nodes)) } @@ -401,8 +407,10 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) { "directives: %v", err) } - if len(candidates) != len(nodes) { - t1.Fatalf("all nodes should be scored, "+ + // We expect two candidates, since one of the nodes + // doesn't have any channels. + if len(candidates) != 2 { + t1.Fatalf("2 nodes should be scored, "+ "instead %v were", len(candidates)) }