From 3bc58a0d2fc9164aa4c7efeb40dc9eadca013602 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 9 May 2025 12:51:27 +0200 Subject: [PATCH] graph/db: test the non-cached version of ForEachNodeDirectedChannel Expand an existing test for ForEachNodeDirectedChannel so that it also tests the DB method and not just the ChannelGraph method which will use the in-memory graph cache for the query. --- graph/db/graph_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index 62f153ede..12e33a960 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -1320,7 +1320,17 @@ func TestGraphTraversalCacheable(t *testing.T) { require.NoError(t, err) require.Len(t, nodeMap, 0) + // Duplicate the map before we start deleting from it so that we can + // check that both the cached and db version of + // ForEachNodeDirectedChannel works as expected here. + chanIndex2 := make(map[uint64]struct{}) + for k, v := range chanIndex { + chanIndex2[k] = v + } + for _, node := range nodes { + // Query the ChannelGraph which uses the cache to iterate + // through the channels for each node. err = graph.ForEachNodeDirectedChannel( node, func(d *DirectedChannel) error { delete(chanIndex, d.ChannelID) @@ -1328,8 +1338,18 @@ func TestGraphTraversalCacheable(t *testing.T) { }, ) require.NoError(t, err) + + // Now skip the cache and query the DB directly. + err = graph.V1Store.ForEachNodeDirectedChannel( + node, func(d *DirectedChannel) error { + delete(chanIndex2, d.ChannelID) + return nil + }, + ) + require.NoError(t, err) } require.Len(t, chanIndex, 0) + require.Len(t, chanIndex2, 0) } func TestGraphCacheTraversal(t *testing.T) {