itest: save temp miner's logs
This commit is contained in:
2 files changed
+74
-47
No files matched your search
@@ -19,6 +19,8 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/integration/rpctest"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/go-errors/errors"
|
||||
@@ -351,6 +353,59 @@ func newNode(cfg NodeConfig) (*HarnessNode, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewMiner creates a new miner using btcd backend. The logDir specifies the
|
||||
// miner node's log dir. When tests finished, during clean up, its logs are
|
||||
// copied to a file specified as logFilename.
|
||||
func NewMiner(logDir, logFilename string, netParams *chaincfg.Params,
|
||||
handler *rpcclient.NotificationHandlers) (*rpctest.Harness,
|
||||
func() error, error) {
|
||||
|
||||
args := []string{
|
||||
"--rejectnonstd",
|
||||
"--txindex",
|
||||
"--nowinservice",
|
||||
"--nobanning",
|
||||
"--debuglevel=debug",
|
||||
"--logdir=" + logDir,
|
||||
"--trickleinterval=100ms",
|
||||
}
|
||||
|
||||
miner, err := rpctest.New(netParams, handler, args)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf(
|
||||
"unable to create mining node: %v", err,
|
||||
)
|
||||
}
|
||||
|
||||
cleanUp := func() error {
|
||||
if err := miner.TearDown(); err != nil {
|
||||
return fmt.Errorf(
|
||||
"failed to tear down miner, got error: %s", err,
|
||||
)
|
||||
}
|
||||
|
||||
// After shutting down the miner, we'll make a copy of the log
|
||||
// file before deleting the temporary log dir.
|
||||
logFile := fmt.Sprintf(
|
||||
"%s/%s/btcd.log", logDir, netParams.Name,
|
||||
)
|
||||
copyPath := fmt.Sprintf("./%s", logFilename)
|
||||
err := CopyFile(copyPath, logFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to copy file: %v", err)
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(logDir); err != nil {
|
||||
return fmt.Errorf(
|
||||
"cannot remove dir %s: %v", logDir, err,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return miner, cleanUp, nil
|
||||
}
|
||||
|
||||
// DBPath returns the filepath to the channeldb database file for this node.
|
||||
func (hn *HarnessNode) DBPath() string {
|
||||
return hn.Cfg.DBPath()
|
||||
|
||||
Reference in new issue
Block a user