From e412fe5a94c01d695fc702dec5797675c9b77822 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 12 Oct 2021 17:53:29 -0400 Subject: [PATCH] fix tests --- internal/blocksync/v0/reactor_test.go | 2 +- internal/consensus/replay_test.go | 12 ++-- internal/proxy/app_conn.go | 90 ++++++++++++++++++--------- internal/proxy/multi_app_conn_test.go | 2 +- internal/state/execution_test.go | 10 +-- internal/state/helpers_test.go | 2 +- node/node_test.go | 6 +- node/setup.go | 2 +- 8 files changed, 78 insertions(+), 48 deletions(-) diff --git a/internal/blocksync/v0/reactor_test.go b/internal/blocksync/v0/reactor_test.go index e947581aa..312b1cb39 100644 --- a/internal/blocksync/v0/reactor_test.go +++ b/internal/blocksync/v0/reactor_test.go @@ -98,7 +98,7 @@ func (rts *reactorTestSuite) addNode(t *testing.T, t.Helper() rts.nodes = append(rts.nodes, nodeID) - rts.app[nodeID] = proxy.NewAppConns(abciclient.NewLocalCreator(&abci.BaseApplication{})) + rts.app[nodeID] = proxy.NewAppConns(abciclient.NewLocalCreator(&abci.BaseApplication{}), proxy.NopMetrics()) require.NoError(t, rts.app[nodeID].Start()) blockDB := dbm.NewMemDB() diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index 97017985d..0d0ae36e8 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -745,7 +745,7 @@ func testHandshakeReplay(t *testing.T, sim *simulatorTestSuite, nBlocks int, mod if nBlocks > 0 { // run nBlocks against a new client to build up the app state. // use a throwaway tendermint state - proxyApp := proxy.NewAppConns(clientCreator2) + proxyApp := proxy.NewAppConns(clientCreator2, proxy.NopMetrics()) stateDB1 := dbm.NewMemDB() stateStore := sm.NewStore(stateDB1) err := stateStore.Save(genesisState) @@ -765,7 +765,7 @@ func testHandshakeReplay(t *testing.T, sim *simulatorTestSuite, nBlocks int, mod // now start the app using the handshake - it should sync genDoc, _ := sm.MakeGenesisDocFromFile(cfg.GenesisFile()) handshaker := NewHandshaker(stateStore, state, store, genDoc) - proxyApp := proxy.NewAppConns(clientCreator2) + proxyApp := proxy.NewAppConns(clientCreator2, proxy.NopMetrics()) if err := proxyApp.Start(); err != nil { t.Fatalf("Error starting proxy app connections: %v", err) } @@ -893,7 +893,7 @@ func buildTMStateFromChain( defer kvstoreApp.Close() clientCreator := abciclient.NewLocalCreator(kvstoreApp) - proxyApp := proxy.NewAppConns(clientCreator) + proxyApp := proxy.NewAppConns(clientCreator, proxy.NopMetrics()) if err := proxyApp.Start(); err != nil { panic(err) } @@ -960,7 +960,7 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) { { app := &badApp{numBlocks: 3, allHashesAreWrong: true} clientCreator := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(clientCreator) + proxyApp := proxy.NewAppConns(clientCreator, proxy.NopMetrics()) err := proxyApp.Start() require.NoError(t, err) t.Cleanup(func() { @@ -984,7 +984,7 @@ func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) { { app := &badApp{numBlocks: 3, onlyLastHashIsWrong: true} clientCreator := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(clientCreator) + proxyApp := proxy.NewAppConns(clientCreator, proxy.NopMetrics()) err := proxyApp.Start() require.NoError(t, err) t.Cleanup(func() { @@ -1243,7 +1243,7 @@ func TestHandshakeUpdatesValidators(t *testing.T) { // now start the app using the handshake - it should sync genDoc, _ := sm.MakeGenesisDocFromFile(cfg.GenesisFile()) handshaker := NewHandshaker(stateStore, state, store, genDoc) - proxyApp := proxy.NewAppConns(clientCreator) + proxyApp := proxy.NewAppConns(clientCreator, proxy.NopMetrics()) if err := proxyApp.Start(); err != nil { t.Fatalf("Error starting proxy app connections: %v", err) } diff --git a/internal/proxy/app_conn.go b/internal/proxy/app_conn.go index 4e79120cf..feaf2f02d 100644 --- a/internal/proxy/app_conn.go +++ b/internal/proxy/app_conn.go @@ -81,8 +81,10 @@ func (app *appConnConsensus) InitChainSync( req types.RequestInitChain, ) (*types.ResponseInitChain, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "init_chain", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "init_chain", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.InitChainSync(ctx, req) } @@ -91,8 +93,10 @@ func (app *appConnConsensus) BeginBlockSync( req types.RequestBeginBlock, ) (*types.ResponseBeginBlock, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "begin_block", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "begin_block", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.BeginBlockSync(ctx, req) } @@ -101,8 +105,10 @@ func (app *appConnConsensus) DeliverTxAsync( req types.RequestDeliverTx, ) (*abciclient.ReqRes, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "deliver_tx", - "type", "aync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "deliver_tx", + "type", "aync").Observe(time.Since(start).Seconds()) + }() return app.appConn.DeliverTxAsync(ctx, req) } @@ -111,15 +117,19 @@ func (app *appConnConsensus) EndBlockSync( req types.RequestEndBlock, ) (*types.ResponseEndBlock, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "deliver_tx", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "deliver_tx", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.EndBlockSync(ctx, req) } func (app *appConnConsensus) CommitSync(ctx context.Context) (*types.ResponseCommit, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "commit", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "commit", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.CommitSync(ctx) } @@ -148,15 +158,19 @@ func (app *appConnMempool) Error() error { func (app *appConnMempool) FlushAsync(ctx context.Context) (*abciclient.ReqRes, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "flush", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "flush", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.FlushAsync(ctx) } func (app *appConnMempool) FlushSync(ctx context.Context) error { start := time.Now() - defer app.metrics.MethodTiming.With("method", "flush", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "flush", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.FlushSync(ctx) } @@ -169,8 +183,10 @@ func (app *appConnMempool) CheckTxAsync(ctx context.Context, req types.RequestCh func (app *appConnMempool) CheckTxSync(ctx context.Context, req types.RequestCheckTx) (*types.ResponseCheckTx, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "check_tx", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "check_tx", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.CheckTxSync(ctx, req) } @@ -195,22 +211,28 @@ func (app *appConnQuery) Error() error { func (app *appConnQuery) EchoSync(ctx context.Context, msg string) (*types.ResponseEcho, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "echo", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "echo", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.EchoSync(ctx, msg) } func (app *appConnQuery) InfoSync(ctx context.Context, req types.RequestInfo) (*types.ResponseInfo, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "info", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "info", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.InfoSync(ctx, req) } func (app *appConnQuery) QuerySync(ctx context.Context, reqQuery types.RequestQuery) (*types.ResponseQuery, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "query", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "query", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.QuerySync(ctx, reqQuery) } @@ -238,8 +260,10 @@ func (app *appConnSnapshot) ListSnapshotsSync( req types.RequestListSnapshots, ) (*types.ResponseListSnapshots, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "list_snapshots", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "list_snapshots", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.ListSnapshotsSync(ctx, req) } @@ -248,8 +272,10 @@ func (app *appConnSnapshot) OfferSnapshotSync( req types.RequestOfferSnapshot, ) (*types.ResponseOfferSnapshot, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "offer_snapshot", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "offer_snapshot", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.OfferSnapshotSync(ctx, req) } @@ -257,8 +283,10 @@ func (app *appConnSnapshot) LoadSnapshotChunkSync( ctx context.Context, req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "load_snapshot_chunk", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "load_snapshot_chunk", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.LoadSnapshotChunkSync(ctx, req) } @@ -266,7 +294,9 @@ func (app *appConnSnapshot) ApplySnapshotChunkSync( ctx context.Context, req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) { start := time.Now() - defer app.metrics.MethodTiming.With("method", "apply_snapshot_chunk", - "type", "sync").Observe(time.Since(start).Seconds()) + defer func() { + app.metrics.MethodTiming.With("method", "apply_snapshot_chunk", + "type", "sync").Observe(time.Since(start).Seconds()) + }() return app.appConn.ApplySnapshotChunkSync(ctx, req) } diff --git a/internal/proxy/multi_app_conn_test.go b/internal/proxy/multi_app_conn_test.go index 55bcc7524..a17c39fd4 100644 --- a/internal/proxy/multi_app_conn_test.go +++ b/internal/proxy/multi_app_conn_test.go @@ -31,7 +31,7 @@ func TestAppConns_Start_Stop(t *testing.T) { return clientMock, nil } - appConns := NewAppConns(creator) + appConns := NewAppConns(creator, NopMetrics()) err := appConns.Start() require.NoError(t, err) diff --git a/internal/state/execution_test.go b/internal/state/execution_test.go index 8eff0430d..a66b677f9 100644 --- a/internal/state/execution_test.go +++ b/internal/state/execution_test.go @@ -36,7 +36,7 @@ var ( func TestApplyBlock(t *testing.T) { app := &testApp{} cc := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests @@ -61,7 +61,7 @@ func TestApplyBlock(t *testing.T) { func TestBeginBlockValidators(t *testing.T) { app := &testApp{} cc := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // no need to check error again @@ -124,7 +124,7 @@ func TestBeginBlockValidators(t *testing.T) { func TestBeginBlockByzantineValidators(t *testing.T) { app := &testApp{} cc := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests @@ -349,7 +349,7 @@ func TestUpdateValidators(t *testing.T) { func TestEndBlockValidatorUpdates(t *testing.T) { app := &testApp{} cc := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests @@ -422,7 +422,7 @@ func TestEndBlockValidatorUpdates(t *testing.T) { func TestEndBlockValidatorUpdatesResultingInEmptySet(t *testing.T) { app := &testApp{} cc := abciclient.NewLocalCreator(app) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests diff --git a/internal/state/helpers_test.go b/internal/state/helpers_test.go index f8ed77b32..0cedebb00 100644 --- a/internal/state/helpers_test.go +++ b/internal/state/helpers_test.go @@ -31,7 +31,7 @@ type paramsChangeTestCase struct { func newTestApp() proxy.AppConns { app := &testApp{} cc := abciclient.NewLocalCreator(app) - return proxy.NewAppConns(cc) + return proxy.NewAppConns(cc, proxy.NopMetrics()) } func makeAndCommitGoodBlock( diff --git a/node/node_test.go b/node/node_test.go index 30e7a8f13..8d225fa09 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -214,7 +214,7 @@ func TestCreateProposalBlock(t *testing.T) { cfg := config.ResetTestRoot("node_create_proposal") defer os.RemoveAll(cfg.RootDir) cc := abciclient.NewLocalCreator(kvstore.NewApplication()) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests @@ -306,7 +306,7 @@ func TestMaxTxsProposalBlockSize(t *testing.T) { cfg := config.ResetTestRoot("node_create_proposal") defer os.RemoveAll(cfg.RootDir) cc := abciclient.NewLocalCreator(kvstore.NewApplication()) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests @@ -368,7 +368,7 @@ func TestMaxProposalBlockSize(t *testing.T) { cfg := config.ResetTestRoot("node_create_proposal") defer os.RemoveAll(cfg.RootDir) cc := abciclient.NewLocalCreator(kvstore.NewApplication()) - proxyApp := proxy.NewAppConns(cc) + proxyApp := proxy.NewAppConns(cc, proxy.NopMetrics()) err := proxyApp.Start() require.Nil(t, err) defer proxyApp.Stop() //nolint:errcheck // ignore for tests diff --git a/node/setup.go b/node/setup.go index 10a420aea..4e0ef0929 100644 --- a/node/setup.go +++ b/node/setup.go @@ -48,7 +48,7 @@ func initDBs(cfg *config.Config, dbProvider config.DBProvider) (blockStore *stor } func createAndStartProxyAppConns(clientCreator abciclient.Creator, logger log.Logger, metrics *proxy.Metrics) (proxy.AppConns, error) { - proxyApp := proxy.NewAppConns(clientCreator, metrics) + proxyApp := proxy.NewAppConns(clientCreator, metrics, proxy.NopMetrics()) proxyApp.SetLogger(logger.With("module", "proxy")) if err := proxyApp.Start(); err != nil { return nil, fmt.Errorf("error starting proxy app connections: %v", err)