Merge pull request #3797 from joostjager/explicit-now-dependency-channeldb

channeldb: inject clock into database
This commit is contained in:
Joost Jager
2020-01-23 14:27:02 +01:00
committed by GitHub
7 changed files with 29 additions and 15 deletions

View File

@@ -317,7 +317,7 @@ func TestCancelInvoice(t *testing.T) {
func TestSettleHoldInvoice(t *testing.T) {
defer timeout()()
cdb, cleanup, err := newTestChannelDB()
cdb, cleanup, err := newTestChannelDB(clock.NewTestClock(time.Time{}))
if err != nil {
t.Fatal(err)
}
@@ -497,7 +497,7 @@ func TestSettleHoldInvoice(t *testing.T) {
func TestCancelHoldInvoice(t *testing.T) {
defer timeout()()
cdb, cleanup, err := newTestChannelDB()
cdb, cleanup, err := newTestChannelDB(clock.NewTestClock(time.Time{}))
if err != nil {
t.Fatal(err)
}
@@ -798,7 +798,7 @@ func TestMppPayment(t *testing.T) {
func TestInvoiceExpiryWithRegistry(t *testing.T) {
t.Parallel()
cdb, cleanup, err := newTestChannelDB()
cdb, cleanup, err := newTestChannelDB(clock.NewTestClock(time.Time{}))
defer cleanup()
if err != nil {

View File

@@ -110,7 +110,7 @@ var (
}
)
func newTestChannelDB() (*channeldb.DB, func(), error) {
func newTestChannelDB(clock clock.Clock) (*channeldb.DB, func(), error) {
// First, create a temporary directory to be used for the duration of
// this test.
tempDirName, err := ioutil.TempDir("", "channeldb")
@@ -119,7 +119,9 @@ func newTestChannelDB() (*channeldb.DB, func(), error) {
}
// Next, create channeldb for the first time.
cdb, err := channeldb.Open(tempDirName)
cdb, err := channeldb.Open(
tempDirName, channeldb.OptionClock(clock),
)
if err != nil {
os.RemoveAll(tempDirName)
return nil, nil, err
@@ -145,11 +147,10 @@ type testContext struct {
func newTestContext(t *testing.T) *testContext {
clock := clock.NewTestClock(testTime)
cdb, cleanup, err := newTestChannelDB()
cdb, cleanup, err := newTestChannelDB(clock)
if err != nil {
t.Fatal(err)
}
cdb.Now = clock.Now
expiryWatcher := NewInvoiceExpiryWatcher(clock)