Skip to content

Commit

Permalink
rpctest: fix appdata vs datadir issue (#342)
Browse files Browse the repository at this point in the history

From @jrick diff, only use appdata instead of both datadir and logdir.
Remove Shutdown() and instead explicitly call Stop/Cleanup()
Fixes #340
  • Loading branch information
alexlyp committed Sep 20, 2016
1 parent 1a8c312 commit 867b3bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 68 deletions.
64 changes: 13 additions & 51 deletions rpctest/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ type nodeConfig struct {
listen string
rpcListen string
rpcConnect string
dataDir string
logDir string
profile string
debugLevel string
extra []string
prefix string
appDataDir string

exe string
endpoint string
Expand All @@ -44,15 +42,15 @@ type nodeConfig struct {
}

// newConfig returns a nodeConfig with default values.
func newConfig(prefix, certFile, keyFile string, extra []string) (*nodeConfig, error) {
func newConfig(appDataDir, certFile, keyFile string, extra []string) (*nodeConfig, error) {
// TODO: use defaultP2pPort and defaultRPCPort instead of literals
a := &nodeConfig{
listen: "127.0.0.1:18555",
rpcListen: "127.0.0.1:19556",
rpcUser: "user",
rpcPass: "pass",
extra: extra,
prefix: prefix,
listen: "127.0.0.1:18555",
rpcListen: "127.0.0.1:19556",
rpcUser: "user",
rpcPass: "pass",
extra: extra,
appDataDir: appDataDir,

exe: "dcrd",
endpoint: "ws",
Expand All @@ -69,16 +67,6 @@ func newConfig(prefix, certFile, keyFile string, extra []string) (*nodeConfig, e
// temporary data, and log directories which must be cleaned up with a call to
// cleanup().
func (n *nodeConfig) setDefaults() error {
datadir, err := ioutil.TempDir(n.prefix, "data")
if err != nil {
return err
}
n.dataDir = datadir
logdir, err := ioutil.TempDir(n.prefix, "logs")
if err != nil {
return err
}
n.logDir = logdir
cert, err := ioutil.ReadFile(n.certFile)
if err != nil {
return err
Expand Down Expand Up @@ -117,14 +105,7 @@ func (n *nodeConfig) arguments() []string {
args = append(args, fmt.Sprintf("--rpccert=%s", n.certFile))
// --rpckey
args = append(args, fmt.Sprintf("--rpckey=%s", n.keyFile))
if n.dataDir != "" {
// --datadir
args = append(args, fmt.Sprintf("--datadir=%s", n.dataDir))
}
if n.logDir != "" {
// --logdir
args = append(args, fmt.Sprintf("--logdir=%s", n.logDir))
}
args = append(args, fmt.Sprintf("--appdata=%s", n.appDataDir))
if n.profile != "" {
// --profile
args = append(args, fmt.Sprintf("--profile=%s", n.profile))
Expand Down Expand Up @@ -159,22 +140,15 @@ func (n *nodeConfig) rpcConnConfig() rpc.ConnConfig {

// String returns the string representation of this nodeConfig.
func (n *nodeConfig) String() string {
return n.prefix
return n.appDataDir
}

// cleanup removes the tmp data and log directories.
func (n *nodeConfig) cleanup() error {
dirs := []string{
n.logDir,
n.dataDir,
}
var err error
for _, dir := range dirs {
if err = os.RemoveAll(dir); err != nil {
log.Printf("Cannot remove dir %s: %v", dir, err)
}
if err := os.RemoveAll(n.appDataDir); err != nil {
return err
}
return err
return nil
}

// node houses the neccessary state required to configure, launch, and manaage
Expand Down Expand Up @@ -266,18 +240,6 @@ func (n *node) Cleanup() error {
return n.config.cleanup()
}

// shutdown terminates the running dcrd process, and cleans up all
// file/directories created by node.
func (n *node) Shutdown() error {
if err := n.Stop(); err != nil {
return err
}
if err := n.Cleanup(); err != nil {
return err
}
return nil
}

// genCertPair generates a key/cert pair to the paths provided.
func genCertPair(certFile, keyFile, certFileWallet, keyFileWallet string) error {
org := "rpctest autogenerated cert"
Expand Down
16 changes: 11 additions & 5 deletions rpctest/rpcharness.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error {
miningArg := fmt.Sprintf("--miningaddr=%s", miningAddr)
extraArgs = append(extraArgs, miningArg)

// Shutdown node so we can restart it with --miningaddr
if err := h.node.Shutdown(); err != nil {
// Stop node so we can restart it with --miningaddr
if err := h.node.Stop(); err != nil {
return err
}

config, err := newConfig(h.node.config.prefix, h.node.config.certFile,
config, err := newConfig(h.node.config.appDataDir, h.node.config.certFile,
h.node.config.keyFile, extraArgs)
if err != nil {
return err
Expand Down Expand Up @@ -313,10 +313,16 @@ func (h *Harness) TearDown() error {
h.Node.Shutdown()
}

if err := h.node.Shutdown(); err != nil {
if err := h.node.Stop(); err != nil {
return err
}
if err := h.wallet.Shutdown(); err != nil {
if err := h.node.Cleanup(); err != nil {
return err
}
if err := h.wallet.Stop(); err != nil {
return err
}
if err := h.wallet.Cleanup(); err != nil {
return err
}

Expand Down
12 changes: 0 additions & 12 deletions rpctest/walletnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,3 @@ func (n *walletTest) Cleanup() error {

return n.config.cleanup()
}

// Shutdown terminates the running dcrwallet process, and cleans up all
// file/directories created by walletTest.
func (n *walletTest) Shutdown() error {
if err := n.Stop(); err != nil {
return err
}
if err := n.Cleanup(); err != nil {
return err
}
return nil
}

0 comments on commit 867b3bb

Please sign in to comment.