multi: rename chan DB Open method to OpenForTesting

This commit is contained in:
Elle Mouton committed 2024-11-28 13:51:15 +02:00
1 parent 4089fbcb44
commit 439a6c7d6c
24 files changed
+101 -331

No files matched your search

+1 -3
View File
@@ -625,9 +625,7 @@ func makeCircuitDB(t *testing.T, path string) *channeldb.DB {
path = t.TempDir()
}
db, err := channeldb.Open(path)
require.NoError(t, err, "unable to open channel db")
t.Cleanup(func() { db.Close() })
db := channeldb.OpenForTesting(t, path)
return db
}
+1 -2
View File
@@ -2169,7 +2169,7 @@ func newSingleLinkTestHarness(t *testing.T, chanAmt,
BaseFee: lnwire.NewMSatFromSatoshis(1),
TimeLockDelta: 6,
}
invoiceRegistry = newMockRegistry(globalPolicy.TimeLockDelta)
invoiceRegistry = newMockRegistry(t)
)
pCache := newMockPreimageCache()
@@ -2267,7 +2267,6 @@ func newSingleLinkTestHarness(t *testing.T, chanAmt,
t.Cleanup(func() {
close(alicePeer.quit)
invoiceRegistry.cleanup()
})
harness := singleLinkTestHarness{
+4 -40
View File
@@ -8,7 +8,6 @@ import (
"fmt"
"io"
"net"
"os"
"path/filepath"
"sync"
"sync/atomic"
@@ -216,11 +215,7 @@ func initSwitchWithTempDB(t testing.TB, startingHeight uint32) (*Switch,
error) {
tempPath := filepath.Join(t.TempDir(), "switchdb")
db, err := channeldb.Open(tempPath)
if err != nil {
return nil, err
}
t.Cleanup(func() { db.Close() })
db := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(startingHeight, db)
if err != nil {
@@ -254,9 +249,7 @@ func newMockServer(t testing.TB, name string, startingHeight uint32,
t.Cleanup(func() { _ = htlcSwitch.Stop() })
registry := newMockRegistry(defaultDelta)
t.Cleanup(func() { registry.cleanup() })
registry := newMockRegistry(t)
return &mockServer{
t: t,
@@ -977,37 +970,12 @@ func (f *mockChannelLink) CommitmentCustomBlob() fn.Option[tlv.Blob] {
var _ ChannelLink = (*mockChannelLink)(nil)
func newDB() (*channeldb.DB, func(), error) {
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName, err := os.MkdirTemp("", "channeldb")
if err != nil {
return nil, nil, err
}
// Next, create channeldb for the first time.
cdb, err := channeldb.Open(tempDirName)
if err != nil {
os.RemoveAll(tempDirName)
return nil, nil, err
}
cleanUp := func() {
cdb.Close()
os.RemoveAll(tempDirName)
}
return cdb, cleanUp, nil
}
const testInvoiceCltvExpiry = 6
type mockInvoiceRegistry struct {
settleChan chan lntypes.Hash
registry *invoices.InvoiceRegistry
cleanup func()
}
type mockChainNotifier struct {
@@ -1024,11 +992,8 @@ func (m *mockChainNotifier) RegisterBlockEpochNtfn(*chainntnfs.BlockEpoch) (
}, nil
}
func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
cdb, cleanup, err := newDB()
if err != nil {
panic(err)
}
func newMockRegistry(t testing.TB) *mockInvoiceRegistry {
cdb := channeldb.OpenForTesting(t, t.TempDir())
modifierMock := &invoices.MockHtlcModifier{}
registry := invoices.NewRegistry(
@@ -1046,7 +1011,6 @@ func newMockRegistry(minDelta uint32) *mockInvoiceRegistry {
return &mockInvoiceRegistry{
registry: registry,
cleanup: cleanup,
}
}
+1 -5
View File
@@ -101,11 +101,7 @@ func TestNetworkResultStore(t *testing.T) {
const numResults = 4
db, err := channeldb.Open(t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { db.Close() })
db := channeldb.OpenForTesting(t, t.TempDir())
store := newNetworkResultStore(db)
+16 -48
View File
@@ -1002,9 +1002,7 @@ func TestSwitchForwardFailAfterFullAdd(t *testing.T) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to open channeldb")
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err, "unable to init switch")
@@ -1096,9 +1094,7 @@ func TestSwitchForwardFailAfterFullAdd(t *testing.T) {
t.Fatalf(err.Error())
}
cdb2, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to reopen channeldb")
t.Cleanup(func() { cdb2.Close() })
cdb2 := channeldb.OpenForTesting(t, tempPath)
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
require.NoError(t, err, "unable reinit switch")
@@ -1192,9 +1188,7 @@ func TestSwitchForwardSettleAfterFullAdd(t *testing.T) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to open channeldb")
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err, "unable to init switch")
@@ -1286,9 +1280,7 @@ func TestSwitchForwardSettleAfterFullAdd(t *testing.T) {
t.Fatalf(err.Error())
}
cdb2, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to reopen channeldb")
t.Cleanup(func() { cdb2.Close() })
cdb2 := channeldb.OpenForTesting(t, tempPath)
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
require.NoError(t, err, "unable reinit switch")
@@ -1385,9 +1377,7 @@ func TestSwitchForwardDropAfterFullAdd(t *testing.T) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to open channeldb")
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err, "unable to init switch")
@@ -1471,9 +1461,7 @@ func TestSwitchForwardDropAfterFullAdd(t *testing.T) {
t.Fatalf(err.Error())
}
cdb2, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to reopen channeldb")
t.Cleanup(func() { cdb2.Close() })
cdb2 := channeldb.OpenForTesting(t, tempPath)
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
require.NoError(t, err, "unable reinit switch")
@@ -1541,9 +1529,7 @@ func TestSwitchForwardFailAfterHalfAdd(t *testing.T) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to open channeldb")
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err, "unable to init switch")
@@ -1622,9 +1608,7 @@ func TestSwitchForwardFailAfterHalfAdd(t *testing.T) {
t.Fatalf(err.Error())
}
cdb2, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to reopen channeldb")
t.Cleanup(func() { cdb2.Close() })
cdb2 := channeldb.OpenForTesting(t, tempPath)
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
require.NoError(t, err, "unable reinit switch")
@@ -1698,9 +1682,7 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to open channeldb")
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err, "unable to init switch")
@@ -1778,9 +1760,7 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) {
t.Fatalf(err.Error())
}
cdb2, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to reopen channeldb")
t.Cleanup(func() { cdb2.Close() })
cdb2 := channeldb.OpenForTesting(t, tempPath)
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
require.NoError(t, err, "unable reinit switch")
@@ -1870,9 +1850,7 @@ func TestSwitchForwardCircuitPersistence(t *testing.T) {
t.Fatalf(err.Error())
}
cdb3, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to reopen channeldb")
t.Cleanup(func() { cdb3.Close() })
cdb3 := channeldb.OpenForTesting(t, tempPath)
s3, err := initSwitchWithDB(testStartingHeight, cdb3)
require.NoError(t, err, "unable reinit switch")
@@ -3827,9 +3805,7 @@ func newInterceptableSwitchTestContext(
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err, "unable to open channeldb")
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err, "unable to init switch")
@@ -4914,9 +4890,7 @@ func testSwitchForwardFailAlias(t *testing.T, zeroConf bool) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err)
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err)
@@ -4990,9 +4964,7 @@ func testSwitchForwardFailAlias(t *testing.T, zeroConf bool) {
err = cdb.Close()
require.NoError(t, err)
cdb2, err := channeldb.Open(tempPath)
require.NoError(t, err)
t.Cleanup(func() { cdb2.Close() })
cdb2 := channeldb.OpenForTesting(t, tempPath)
s2, err := initSwitchWithDB(testStartingHeight, cdb2)
require.NoError(t, err)
@@ -5130,9 +5102,7 @@ func testSwitchAliasFailAdd(t *testing.T, zeroConf, private, useAlias bool) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err)
defer cdb.Close()
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err)
@@ -5471,9 +5441,7 @@ func testSwitchAliasInterceptFail(t *testing.T, zeroConf bool) {
tempPath := t.TempDir()
cdb, err := channeldb.Open(tempPath)
require.NoError(t, err)
t.Cleanup(func() { cdb.Close() })
cdb := channeldb.OpenForTesting(t, tempPath)
s, err := initSwitchWithDB(testStartingHeight, cdb)
require.NoError(t, err)
+4 -21
View File
@@ -251,21 +251,8 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
return nil, nil, err
}
dbAlice, err := channeldb.Open(t.TempDir())
if err != nil {
return nil, nil, err
}
t.Cleanup(func() {
require.NoError(t, dbAlice.Close())
})
dbBob, err := channeldb.Open(t.TempDir())
if err != nil {
return nil, nil, err
}
t.Cleanup(func() {
require.NoError(t, dbBob.Close())
})
dbAlice := channeldb.OpenForTesting(t, t.TempDir())
dbBob := channeldb.OpenForTesting(t, t.TempDir())
estimator := chainfee.NewStaticEstimator(6000, 0)
feePerKw, err := estimator.EstimateFeePerKW(1)
@@ -403,11 +390,7 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
switch err {
case nil:
case kvdb.ErrDatabaseNotOpen:
dbAlice, err = channeldb.Open(dbAlice.Path())
if err != nil {
return nil, errors.Errorf("unable to reopen alice "+
"db: %v", err)
}
dbAlice = channeldb.OpenForTesting(t, dbAlice.Path())
aliceStoredChannels, err = dbAlice.ChannelStateDB().
FetchOpenChannels(aliceKeyPub)
@@ -451,7 +434,7 @@ func createTestChannel(t *testing.T, alicePrivKey, bobPrivKey []byte,
switch err {
case nil:
case kvdb.ErrDatabaseNotOpen:
dbBob, err = channeldb.Open(dbBob.Path())
dbBob = channeldb.OpenForTesting(t, dbBob.Path())
if err != nil {
return nil, errors.Errorf("unable to reopen bob "+
"db: %v", err)