graph: test cleanup

Remove the kvdb.Backend return type of the `makeTestGraph` helper. This
is in preparation for the helper being used to create a test graph
backed by a DB other than bbolt.
This commit is contained in:
Elle Mouton 2025-03-30 11:30:45 +02:00
parent 424f63b310
commit 4ab0699e10
No known key found for this signature in database
GPG Key ID: D7D916376026F177
2 changed files with 19 additions and 34 deletions

View File

@ -1352,10 +1352,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
testAddrs = append(testAddrs, testAddr)
// Next, create a temporary graph database for usage within the test.
graph, graphBackend, err := makeTestGraph(t, useCache)
if err != nil {
return nil, err
}
graph := makeTestGraph(t, useCache)
aliasMap := make(map[string]route.Vertex)
privKeyMap := make(map[string]*btcec.PrivateKey)
@ -1562,12 +1559,11 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
}
return &testGraphInstance{
graph: graph,
graphBackend: graphBackend,
aliasMap: aliasMap,
privKeyMap: privKeyMap,
channelIDs: channelIDs,
links: links,
graph: graph,
aliasMap: aliasMap,
privKeyMap: privKeyMap,
channelIDs: channelIDs,
links: links,
}, nil
}
@ -1730,10 +1726,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
testAddrs = append(testAddrs, testAddr)
// Next, create a temporary graph database for usage within the test.
graph, graphBackend, err := makeTestGraph(t, useCache)
if err != nil {
return nil, err
}
graph := makeTestGraph(t, useCache)
aliasMap := make(map[string]route.Vertex)
privKeyMap := make(map[string]*btcec.PrivateKey)
@ -1947,11 +1940,10 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
}
return &testGraphInstance{
graph: graph,
graphBackend: graphBackend,
aliasMap: aliasMap,
privKeyMap: privKeyMap,
links: links,
graph: graph,
aliasMap: aliasMap,
privKeyMap: privKeyMap,
links: links,
}, nil
}

View File

@ -1034,8 +1034,7 @@ type testCtx struct {
func createTestCtxSingleNode(t *testing.T,
startingHeight uint32) *testCtx {
graph, graphBackend, err := makeTestGraph(t, true)
require.NoError(t, err, "failed to make test graph")
graph := makeTestGraph(t, true)
sourceNode := createTestNode(t)
@ -1044,8 +1043,7 @@ func createTestCtxSingleNode(t *testing.T,
)
graphInstance := &testGraphInstance{
graph: graph,
graphBackend: graphBackend,
graph: graph,
}
return createTestCtxFromGraphInstance(
@ -1086,14 +1084,12 @@ func (c *testCtx) RestartBuilder(t *testing.T) {
// makeTestGraph creates a new instance of a channeldb.ChannelGraph for testing
// purposes.
func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
kvdb.Backend, error) {
func makeTestGraph(t *testing.T, useCache bool) *graphdb.ChannelGraph {
t.Helper()
// Create channelgraph for the first time.
backend, backendCleanup, err := kvdb.GetTestBackend(t.TempDir(), "cgr")
if err != nil {
return nil, nil, err
}
require.NoError(t, err)
t.Cleanup(backendCleanup)
@ -1101,20 +1097,17 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
&graphdb.Config{KVDB: backend},
graphdb.WithUseGraphCache(useCache),
)
if err != nil {
return nil, nil, err
}
require.NoError(t, err)
require.NoError(t, graph.Start())
t.Cleanup(func() {
require.NoError(t, graph.Stop())
})
return graph, backend, nil
return graph
}
type testGraphInstance struct {
graph *graphdb.ChannelGraph
graphBackend kvdb.Backend
graph *graphdb.ChannelGraph
// aliasMap is a map from a node's alias to its public key. This type is
// provided in order to allow easily look up from the human memorable