mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-15 07:32:39 +02:00
kvdb/etcd: remove context.TODO() from test helpers
We want `context.TODO()` to be high signal in the code-base. It should signal clearly that work is required to thread parent context through to the call-site. So to keep the signal-to-noise ratio high, we remove any context.TODO() calls from tests since these will never need to be replace by a parent context. After this commit, there is only a single context.TODO() left in the code-base.
This commit is contained in:
@ -274,7 +274,7 @@ func GetTestBackend(path, name string) (Backend, func(), error) {
|
||||
return nil, empty, err
|
||||
}
|
||||
backend, err := Open(
|
||||
EtcdBackendName, context.TODO(), etcdConfig,
|
||||
EtcdBackendName, context.Background(), etcdConfig,
|
||||
)
|
||||
return backend, cancel, err
|
||||
|
||||
|
@ -19,7 +19,7 @@ func TestDump(t *testing.T) {
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
db, err := newEtcdBackend(context.Background(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
err = db.Update(func(tx walletdb.ReadWriteTx) error {
|
||||
|
@ -76,7 +76,7 @@ func (f *EtcdTestFixture) NewBackend(singleWriter bool) walletdb.DB {
|
||||
cfg.SingleWriter = true
|
||||
}
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), cfg)
|
||||
db, err := newEtcdBackend(context.Background(), cfg)
|
||||
require.NoError(f.t, err)
|
||||
|
||||
return db
|
||||
@ -84,7 +84,9 @@ func (f *EtcdTestFixture) NewBackend(singleWriter bool) walletdb.DB {
|
||||
|
||||
// Put puts a string key/value into the test etcd database.
|
||||
func (f *EtcdTestFixture) Put(key, value string) {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), testEtcdTimeout)
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), testEtcdTimeout,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
_, err := f.cli.Put(ctx, key, value)
|
||||
@ -95,7 +97,9 @@ func (f *EtcdTestFixture) Put(key, value string) {
|
||||
|
||||
// Get queries a key and returns the stored value from the test etcd database.
|
||||
func (f *EtcdTestFixture) Get(key string) string {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), testEtcdTimeout)
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), testEtcdTimeout,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
resp, err := f.cli.Get(ctx, key)
|
||||
@ -112,7 +116,9 @@ func (f *EtcdTestFixture) Get(key string) string {
|
||||
|
||||
// Dump scans and returns all key/values from the test etcd database.
|
||||
func (f *EtcdTestFixture) Dump() map[string]string {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), testEtcdTimeout)
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), testEtcdTimeout,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
resp, err := f.cli.Get(ctx, "\x00", clientv3.WithFromKey())
|
||||
|
@ -16,7 +16,7 @@ func TestChangeDuringManualTx(t *testing.T) {
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
db, err := newEtcdBackend(context.Background(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
tx, err := db.BeginReadWriteTx()
|
||||
@ -44,7 +44,7 @@ func TestChangeDuringUpdate(t *testing.T) {
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
db, err := newEtcdBackend(context.Background(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
count := 0
|
||||
|
@ -15,5 +15,5 @@ import (
|
||||
func TestWalletDBInterface(t *testing.T) {
|
||||
f := NewEtcdTestFixture(t)
|
||||
cfg := f.BackendConfig()
|
||||
walletdbtest.TestInterface(t, dbType, context.TODO(), &cfg)
|
||||
walletdbtest.TestInterface(t, dbType, context.Background(), &cfg)
|
||||
}
|
||||
|
Reference in New Issue
Block a user