mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
kvdb/etcd: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
945180f0ea
commit
889cb0af47
@ -18,7 +18,6 @@ func TestDump(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
defer f.Cleanup()
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
@ -53,7 +52,6 @@ func TestAbortContext(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
defer f.Cleanup()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
|
@ -21,10 +21,9 @@ const (
|
||||
|
||||
// EtcdTestFixture holds internal state of the etcd test fixture.
|
||||
type EtcdTestFixture struct {
|
||||
t *testing.T
|
||||
cli *clientv3.Client
|
||||
config *Config
|
||||
cleanup func()
|
||||
t *testing.T
|
||||
cli *clientv3.Client
|
||||
config *Config
|
||||
}
|
||||
|
||||
// NewTestEtcdInstance creates an embedded etcd instance for testing, listening
|
||||
@ -47,6 +46,7 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
config, etcdCleanup := NewTestEtcdInstance(t, tmpDir)
|
||||
t.Cleanup(etcdCleanup)
|
||||
|
||||
cli, err := clientv3.New(clientv3.Config{
|
||||
Endpoints: []string{config.Host},
|
||||
@ -63,10 +63,9 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
|
||||
cli.Lease = namespace.NewLease(cli.Lease, defaultNamespace)
|
||||
|
||||
return &EtcdTestFixture{
|
||||
t: t,
|
||||
cli: cli,
|
||||
config: config,
|
||||
cleanup: etcdCleanup,
|
||||
t: t,
|
||||
cli: cli,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,9 +132,3 @@ func (f *EtcdTestFixture) Dump() map[string]string {
|
||||
func (f *EtcdTestFixture) BackendConfig() Config {
|
||||
return *f.config
|
||||
}
|
||||
|
||||
// Cleanup should be called at test fixture teardown to stop the embedded
|
||||
// etcd instance and remove all temp db files form the filesystem.
|
||||
func (f *EtcdTestFixture) Cleanup() {
|
||||
f.cleanup()
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ func TestChangeDuringManualTx(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
defer f.Cleanup()
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
@ -44,7 +43,6 @@ func TestChangeDuringUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f := NewEtcdTestFixture(t)
|
||||
defer f.Cleanup()
|
||||
|
||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
@ -26,11 +26,10 @@ func TestPutToEmpty(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
txQueue := NewCommitQueue(ctx)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
cancel()
|
||||
f.Cleanup()
|
||||
txQueue.Stop()
|
||||
}()
|
||||
})
|
||||
|
||||
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
@ -54,11 +53,10 @@ func TestGetPutDel(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
txQueue := NewCommitQueue(ctx)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
cancel()
|
||||
f.Cleanup()
|
||||
txQueue.Stop()
|
||||
}()
|
||||
})
|
||||
|
||||
testKeyValues := []KV{
|
||||
{"a", "1"},
|
||||
@ -156,11 +154,10 @@ func testFirstLastNextPrev(t *testing.T, prefetchKeys []string,
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
txQueue := NewCommitQueue(ctx)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
cancel()
|
||||
f.Cleanup()
|
||||
txQueue.Stop()
|
||||
}()
|
||||
})
|
||||
|
||||
testKeyValues := []KV{
|
||||
{"kb", "1"},
|
||||
@ -331,11 +328,10 @@ func TestCommitError(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
txQueue := NewCommitQueue(ctx)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
cancel()
|
||||
f.Cleanup()
|
||||
txQueue.Stop()
|
||||
}()
|
||||
})
|
||||
|
||||
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
@ -381,11 +377,10 @@ func TestManualTxError(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
txQueue := NewCommitQueue(ctx)
|
||||
defer func() {
|
||||
t.Cleanup(func() {
|
||||
cancel()
|
||||
f.Cleanup()
|
||||
txQueue.Stop()
|
||||
}()
|
||||
})
|
||||
|
||||
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
||||
require.NoError(t, err)
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
// etcd database driver.
|
||||
func TestWalletDBInterface(t *testing.T) {
|
||||
f := NewEtcdTestFixture(t)
|
||||
defer f.Cleanup()
|
||||
cfg := f.BackendConfig()
|
||||
walletdbtest.TestInterface(t, dbType, context.TODO(), &cfg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user