From 8283ca7ddb5b56090aaa15e005b40782fa618ae7 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Mon, 18 Feb 2019 13:23:40 +0400 Subject: [PATCH] 3291 follow-up (#3323) * changelog: use issue number instead of PR number * follow up to #3291 - rpc/test/helpers.go add StopTendermint(node) func - remove ensureDir(filepath.Dir(walFile), 0700) - mempool/mempool_test.go add type cleanupFunc func() * cmd/show_validator: wrap err to make it more clear --- CHANGELOG_PENDING.md | 7 ++++--- blockchain/store_test.go | 3 ++- cmd/tendermint/commands/show_validator.go | 3 ++- consensus/common_test.go | 3 ++- consensus/replay_test.go | 7 ++----- lite/client/provider_test.go | 6 ++---- lite/proxy/query_test.go | 7 ++----- mempool/mempool_test.go | 6 +++++- node/node.go | 5 +++++ rpc/client/main_test.go | 8 +++----- rpc/grpc/grpc_test.go | 7 +++---- rpc/test/helpers.go | 18 +++++++++++++----- 12 files changed, 45 insertions(+), 35 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 07a8b6267..253d4f98d 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -26,9 +26,10 @@ Special thanks to external contributors on this release: * [consensus] \#3297 Flush WAL on stop to prevent data corruption during graceful shutdown -- [consensus] \#3310 Reset TriggeredTimeoutPrecommit before starting next height +- [consensus] \#3302 Reset TriggeredTimeoutPrecommit before starting next + height - [rpc] \#3251 Fix /net_info#peers#remote_ip format. New format spec: * dotted decimal ("192.0.2.1"), if ip is an IPv4 or IP4-mapped IPv6 address * IPv6 ("2001:db8::1"), if ip is a valid IPv6 address -* [cmd] \#3314 Return an - error on `show_validator` when the private validator file does not exist +* [cmd] \#3314 Return an error on `show_validator` when the private validator + file does not exist diff --git a/blockchain/store_test.go b/blockchain/store_test.go index f1108e722..bd30bc6d2 100644 --- a/blockchain/store_test.go +++ b/blockchain/store_test.go @@ -22,7 +22,8 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" ) -// A cleanupFunc cleans up any config / test files created for a particular test. +// A cleanupFunc cleans up any config / test files created for a particular +// test. type cleanupFunc func() // make a Commit with a single vote containing just the height and a timestamp diff --git a/cmd/tendermint/commands/show_validator.go b/cmd/tendermint/commands/show_validator.go index fbf14f2f6..d76d21970 100644 --- a/cmd/tendermint/commands/show_validator.go +++ b/cmd/tendermint/commands/show_validator.go @@ -3,6 +3,7 @@ package commands import ( "fmt" + "github.com/pkg/errors" "github.com/spf13/cobra" cmn "github.com/tendermint/tendermint/libs/common" @@ -25,7 +26,7 @@ func showValidator(cmd *cobra.Command, args []string) error { pv := privval.LoadFilePV(keyFilePath, config.PrivValidatorStateFile()) bz, err := cdc.MarshalJSON(pv.GetPubKey()) if err != nil { - return err + return errors.Wrap(err, "failed to marshal private validator pubkey") } fmt.Println(string(bz)) diff --git a/consensus/common_test.go b/consensus/common_test.go index 30c1e4b1f..a9fb9e080 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -37,7 +37,8 @@ const ( testSubscriber = "test-client" ) -// A cleanupFunc cleans up any config / test files created for a particular test. +// A cleanupFunc cleans up any config / test files created for a particular +// test. type cleanupFunc func() // genesis, chain_id, priv_val diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 3472fc4bb..136e45b61 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -8,7 +8,6 @@ import ( "io/ioutil" "os" "path" - "path/filepath" "runtime" "testing" "time" @@ -18,17 +17,16 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" abci "github.com/tendermint/tendermint/abci/types" + cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" auto "github.com/tendermint/tendermint/libs/autofile" dbm "github.com/tendermint/tendermint/libs/db" - "github.com/tendermint/tendermint/version" - - cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" + "github.com/tendermint/tendermint/version" ) func TestMain(m *testing.M) { @@ -153,7 +151,6 @@ LOOP: // clean up WAL file from the previous iteration walFile := cs.config.WalFile() - ensureDir(filepath.Dir(walFile), 0700) os.Remove(walFile) // set crashing WAL diff --git a/lite/client/provider_test.go b/lite/client/provider_test.go index 015b0f3de..df49bdd1f 100644 --- a/lite/client/provider_test.go +++ b/lite/client/provider_test.go @@ -15,13 +15,11 @@ import ( func TestMain(m *testing.M) { app := kvstore.NewKVStoreApplication() - node, cleanup := rpctest.StartTendermint(app) - defer cleanup() + node := rpctest.StartTendermint(app) code := m.Run() - node.Stop() - node.Wait() + rpctest.StopTendermint(node) os.Exit(code) } diff --git a/lite/proxy/query_test.go b/lite/proxy/query_test.go index 7a9882595..c1450a5e6 100644 --- a/lite/proxy/query_test.go +++ b/lite/proxy/query_test.go @@ -27,15 +27,12 @@ var waitForEventTimeout = 5 * time.Second // TODO fix tests!! func TestMain(m *testing.M) { - var cleanup func() app := kvstore.NewKVStoreApplication() - node, cleanup = rpctest.StartTendermint(app) + node = rpctest.StartTendermint(app) code := m.Run() - node.Stop() - node.Wait() - cleanup() + rpctest.StopTendermint(node) os.Exit(code) } diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 5e3c71eb2..5d737e190 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -25,7 +25,11 @@ import ( "github.com/tendermint/tendermint/types" ) -func newMempoolWithApp(cc proxy.ClientCreator) (*Mempool, func()) { +// A cleanupFunc cleans up any config / test files created for a particular +// test. +type cleanupFunc func() + +func newMempoolWithApp(cc proxy.ClientCreator) (*Mempool, cleanupFunc) { config := cfg.ResetTestRoot("mempool_test") appConnMem, _ := cc.NewABCIClient() diff --git a/node/node.go b/node/node.go index 969452c40..e5ddd09cc 100644 --- a/node/node.go +++ b/node/node.go @@ -793,6 +793,11 @@ func (n *Node) ProxyApp() proxy.AppConns { return n.proxyApp } +// Config returns the Node's config. +func (n *Node) Config() *cfg.Config { + return n.config +} + //------------------------------------------------------------------------------ func (n *Node) Listeners() []string { diff --git a/rpc/client/main_test.go b/rpc/client/main_test.go index 6961d6507..6ec7b7b0e 100644 --- a/rpc/client/main_test.go +++ b/rpc/client/main_test.go @@ -13,14 +13,12 @@ var node *nm.Node func TestMain(m *testing.M) { // start a tendermint node (and kvstore) in the background to test against - var cleanup func() app := kvstore.NewKVStoreApplication() - node, cleanup = rpctest.StartTendermint(app) + node = rpctest.StartTendermint(app) + code := m.Run() // and shut down proper at the end - node.Stop() - node.Wait() - cleanup() + rpctest.StopTendermint(node) os.Exit(code) } diff --git a/rpc/grpc/grpc_test.go b/rpc/grpc/grpc_test.go index 3a9994989..b82e52226 100644 --- a/rpc/grpc/grpc_test.go +++ b/rpc/grpc/grpc_test.go @@ -15,13 +15,12 @@ import ( func TestMain(m *testing.M) { // start a tendermint node in the background to test against app := kvstore.NewKVStoreApplication() - node, cleanup := rpctest.StartTendermint(app) + node := rpctest.StartTendermint(app) + code := m.Run() // and shut down proper at the end - node.Stop() - node.Wait() - cleanup() + rpctest.StopTendermint(node) os.Exit(code) } diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 50db418a2..10d165625 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -100,8 +100,8 @@ func GetGRPCClient() core_grpc.BroadcastAPIClient { } // StartTendermint starts a test tendermint server in a go routine and returns when it is initialized -func StartTendermint(app abci.Application) (*nm.Node, func()) { - node, cleanup := NewTendermint(app) +func StartTendermint(app abci.Application) *nm.Node { + node := NewTendermint(app) err := node.Start() if err != nil { panic(err) @@ -113,11 +113,19 @@ func StartTendermint(app abci.Application) (*nm.Node, func()) { fmt.Println("Tendermint running!") - return node, cleanup + return node +} + +// StopTendermint stops a test tendermint server, waits until it's stopped and +// cleans up test/config files. +func StopTendermint(node *nm.Node) { + node.Stop() + node.Wait() + os.RemoveAll(node.Config().RootDir) } // NewTendermint creates a new tendermint server and sleeps forever -func NewTendermint(app abci.Application) (*nm.Node, func()) { +func NewTendermint(app abci.Application) *nm.Node { // Create & start node config := GetConfig() logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) @@ -138,5 +146,5 @@ func NewTendermint(app abci.Application) (*nm.Node, func()) { if err != nil { panic(err) } - return node, func() { os.RemoveAll(config.RootDir) } + return node }