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