itest: require no error when cleaning up chainbackends
This commit is contained in:
parent
933d84273a
commit
724f6e0969
@ -3,6 +3,7 @@
|
||||
package lntest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
@ -71,7 +72,7 @@ func (b BitcoindBackendConfig) Name() string {
|
||||
// NewBackend starts a bitcoind node and returns a BitoindBackendConfig for
|
||||
// that node.
|
||||
func NewBackend(miner string, netParams *chaincfg.Params) (
|
||||
*BitcoindBackendConfig, func(), error) {
|
||||
*BitcoindBackendConfig, func() error, error) {
|
||||
|
||||
if netParams != &chaincfg.RegressionNetParams {
|
||||
return nil, nil, fmt.Errorf("only regtest supported")
|
||||
@ -121,21 +122,32 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
|
||||
return nil, nil, fmt.Errorf("couldn't start bitcoind: %v", err)
|
||||
}
|
||||
|
||||
cleanUp := func() {
|
||||
cleanUp := func() error {
|
||||
bitcoind.Process.Kill()
|
||||
bitcoind.Wait()
|
||||
|
||||
var errStr string
|
||||
// After shutting down the chain backend, we'll make a copy of
|
||||
// the log file before deleting the temporary log dir.
|
||||
err := CopyFile("./output_bitcoind_chainbackend.log", logFile)
|
||||
if err != nil {
|
||||
fmt.Printf("unable to copy file: %v\n", err)
|
||||
errStr += fmt.Sprintf("unable to copy file: %v\n", err)
|
||||
}
|
||||
if err = os.RemoveAll(logDir); err != nil {
|
||||
fmt.Printf("Cannot remove dir %s: %v\n", logDir, err)
|
||||
errStr += fmt.Sprintf(
|
||||
"cannot remove dir %s: %v\n", logDir, err,
|
||||
)
|
||||
}
|
||||
|
||||
os.RemoveAll(tempBitcoindDir)
|
||||
if err := os.RemoveAll(tempBitcoindDir); err != nil {
|
||||
errStr += fmt.Sprintf(
|
||||
"cannot remove dir %s: %v\n",
|
||||
tempBitcoindDir, err,
|
||||
)
|
||||
}
|
||||
if errStr != "" {
|
||||
return errors.New(errStr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Allow process to start.
|
||||
|
@ -4,6 +4,7 @@ package lntest
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@ -72,7 +73,7 @@ func (b BtcdBackendConfig) Name() string {
|
||||
// that node. miner should be set to the P2P address of the miner to connect
|
||||
// to.
|
||||
func NewBackend(miner string, netParams *chaincfg.Params) (
|
||||
*BtcdBackendConfig, func(), error) {
|
||||
*BtcdBackendConfig, func() error, error) {
|
||||
|
||||
args := []string{
|
||||
"--rejectnonstd",
|
||||
@ -98,19 +99,28 @@ func NewBackend(miner string, netParams *chaincfg.Params) (
|
||||
minerAddr: miner,
|
||||
}
|
||||
|
||||
cleanUp := func() {
|
||||
chainBackend.TearDown()
|
||||
cleanUp := func() error {
|
||||
var errStr string
|
||||
if err := chainBackend.TearDown(); err != nil {
|
||||
errStr += err.Error() + "\n"
|
||||
}
|
||||
|
||||
// After shutting down the chain backend, we'll make a copy of
|
||||
// the log file before deleting the temporary log dir.
|
||||
logFile := logDir + "/" + netParams.Name + "/btcd.log"
|
||||
err := CopyFile("./output_btcd_chainbackend.log", logFile)
|
||||
if err != nil {
|
||||
fmt.Printf("unable to copy file: %v\n", err)
|
||||
errStr += fmt.Sprintf("unable to copy file: %v\n", err)
|
||||
}
|
||||
if err = os.RemoveAll(logDir); err != nil {
|
||||
fmt.Printf("Cannot remove dir %s: %v\n", logDir, err)
|
||||
errStr += fmt.Sprintf(
|
||||
"cannot remove dir %s: %v\n", logDir, err,
|
||||
)
|
||||
}
|
||||
if errStr != "" {
|
||||
return errors.New(errStr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return bd, cleanUp, nil
|
||||
|
@ -14445,7 +14445,11 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
||||
if err != nil {
|
||||
ht.Fatalf("unable to start backend: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
defer func() {
|
||||
require.NoError(
|
||||
t, cleanUp(), "failed to clean up chain backend",
|
||||
)
|
||||
}()
|
||||
|
||||
if err := miner.SetUp(true, 50); err != nil {
|
||||
ht.Fatalf("unable to set up mining node: %v", err)
|
||||
|
@ -44,12 +44,12 @@ func (b NeutrinoBackendConfig) Name() string {
|
||||
|
||||
// NewBackend starts and returns a NeutrinoBackendConfig for the node.
|
||||
func NewBackend(miner string, _ *chaincfg.Params) (
|
||||
*NeutrinoBackendConfig, func(), error) {
|
||||
*NeutrinoBackendConfig, func() error, error) {
|
||||
|
||||
bd := &NeutrinoBackendConfig{
|
||||
minerAddr: miner,
|
||||
}
|
||||
|
||||
cleanUp := func() {}
|
||||
cleanUp := func() error { return nil }
|
||||
return bd, cleanUp, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user