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.
This commit is contained in:
Elle Mouton
2025-05-09 12:51:27 +02:00
parent be915f2be7
commit 3bc58a0d2f

View File

@@ -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) {