mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +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()
|
t.Parallel()
|
||||||
|
|
||||||
f := NewEtcdTestFixture(t)
|
f := NewEtcdTestFixture(t)
|
||||||
defer f.Cleanup()
|
|
||||||
|
|
||||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -53,7 +52,6 @@ func TestAbortContext(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
f := NewEtcdTestFixture(t)
|
f := NewEtcdTestFixture(t)
|
||||||
defer f.Cleanup()
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
@ -21,10 +21,9 @@ const (
|
|||||||
|
|
||||||
// EtcdTestFixture holds internal state of the etcd test fixture.
|
// EtcdTestFixture holds internal state of the etcd test fixture.
|
||||||
type EtcdTestFixture struct {
|
type EtcdTestFixture struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
cli *clientv3.Client
|
cli *clientv3.Client
|
||||||
config *Config
|
config *Config
|
||||||
cleanup func()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTestEtcdInstance creates an embedded etcd instance for testing, listening
|
// NewTestEtcdInstance creates an embedded etcd instance for testing, listening
|
||||||
@ -47,6 +46,7 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
|
|||||||
tmpDir := t.TempDir()
|
tmpDir := t.TempDir()
|
||||||
|
|
||||||
config, etcdCleanup := NewTestEtcdInstance(t, tmpDir)
|
config, etcdCleanup := NewTestEtcdInstance(t, tmpDir)
|
||||||
|
t.Cleanup(etcdCleanup)
|
||||||
|
|
||||||
cli, err := clientv3.New(clientv3.Config{
|
cli, err := clientv3.New(clientv3.Config{
|
||||||
Endpoints: []string{config.Host},
|
Endpoints: []string{config.Host},
|
||||||
@ -63,10 +63,9 @@ func NewEtcdTestFixture(t *testing.T) *EtcdTestFixture {
|
|||||||
cli.Lease = namespace.NewLease(cli.Lease, defaultNamespace)
|
cli.Lease = namespace.NewLease(cli.Lease, defaultNamespace)
|
||||||
|
|
||||||
return &EtcdTestFixture{
|
return &EtcdTestFixture{
|
||||||
t: t,
|
t: t,
|
||||||
cli: cli,
|
cli: cli,
|
||||||
config: config,
|
config: config,
|
||||||
cleanup: etcdCleanup,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,9 +132,3 @@ func (f *EtcdTestFixture) Dump() map[string]string {
|
|||||||
func (f *EtcdTestFixture) BackendConfig() Config {
|
func (f *EtcdTestFixture) BackendConfig() Config {
|
||||||
return *f.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()
|
t.Parallel()
|
||||||
|
|
||||||
f := NewEtcdTestFixture(t)
|
f := NewEtcdTestFixture(t)
|
||||||
defer f.Cleanup()
|
|
||||||
|
|
||||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -44,7 +43,6 @@ func TestChangeDuringUpdate(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
f := NewEtcdTestFixture(t)
|
f := NewEtcdTestFixture(t)
|
||||||
defer f.Cleanup()
|
|
||||||
|
|
||||||
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
db, err := newEtcdBackend(context.TODO(), f.BackendConfig())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -26,11 +26,10 @@ func TestPutToEmpty(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
txQueue := NewCommitQueue(ctx)
|
txQueue := NewCommitQueue(ctx)
|
||||||
defer func() {
|
t.Cleanup(func() {
|
||||||
cancel()
|
cancel()
|
||||||
f.Cleanup()
|
|
||||||
txQueue.Stop()
|
txQueue.Stop()
|
||||||
}()
|
})
|
||||||
|
|
||||||
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -54,11 +53,10 @@ func TestGetPutDel(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
txQueue := NewCommitQueue(ctx)
|
txQueue := NewCommitQueue(ctx)
|
||||||
defer func() {
|
t.Cleanup(func() {
|
||||||
cancel()
|
cancel()
|
||||||
f.Cleanup()
|
|
||||||
txQueue.Stop()
|
txQueue.Stop()
|
||||||
}()
|
})
|
||||||
|
|
||||||
testKeyValues := []KV{
|
testKeyValues := []KV{
|
||||||
{"a", "1"},
|
{"a", "1"},
|
||||||
@ -156,11 +154,10 @@ func testFirstLastNextPrev(t *testing.T, prefetchKeys []string,
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
txQueue := NewCommitQueue(ctx)
|
txQueue := NewCommitQueue(ctx)
|
||||||
defer func() {
|
t.Cleanup(func() {
|
||||||
cancel()
|
cancel()
|
||||||
f.Cleanup()
|
|
||||||
txQueue.Stop()
|
txQueue.Stop()
|
||||||
}()
|
})
|
||||||
|
|
||||||
testKeyValues := []KV{
|
testKeyValues := []KV{
|
||||||
{"kb", "1"},
|
{"kb", "1"},
|
||||||
@ -331,11 +328,10 @@ func TestCommitError(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
txQueue := NewCommitQueue(ctx)
|
txQueue := NewCommitQueue(ctx)
|
||||||
defer func() {
|
t.Cleanup(func() {
|
||||||
cancel()
|
cancel()
|
||||||
f.Cleanup()
|
|
||||||
txQueue.Stop()
|
txQueue.Stop()
|
||||||
}()
|
})
|
||||||
|
|
||||||
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -381,11 +377,10 @@ func TestManualTxError(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
txQueue := NewCommitQueue(ctx)
|
txQueue := NewCommitQueue(ctx)
|
||||||
defer func() {
|
t.Cleanup(func() {
|
||||||
cancel()
|
cancel()
|
||||||
f.Cleanup()
|
|
||||||
txQueue.Stop()
|
txQueue.Stop()
|
||||||
}()
|
})
|
||||||
|
|
||||||
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
db, err := newEtcdBackend(ctx, f.BackendConfig())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
// etcd database driver.
|
// etcd database driver.
|
||||||
func TestWalletDBInterface(t *testing.T) {
|
func TestWalletDBInterface(t *testing.T) {
|
||||||
f := NewEtcdTestFixture(t)
|
f := NewEtcdTestFixture(t)
|
||||||
defer f.Cleanup()
|
|
||||||
cfg := f.BackendConfig()
|
cfg := f.BackendConfig()
|
||||||
walletdbtest.TestInterface(t, dbType, context.TODO(), &cfg)
|
walletdbtest.TestInterface(t, dbType, context.TODO(), &cfg)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user