From 989fb16d453eba95ff281602076b1d27e7f5b068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Mon, 7 Mar 2022 23:32:07 +0100 Subject: [PATCH] fix: make `TestValidatorSetHandling` stable (#313) Instead of `time.Sleep` a channel is used for reliable synchronization --- CHANGELOG-PENDING.md | 1 + rpc/client/client_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-PENDING.md b/CHANGELOG-PENDING.md index 988d26c7115..5666e945fd0 100644 --- a/CHANGELOG-PENDING.md +++ b/CHANGELOG-PENDING.md @@ -38,5 +38,6 @@ Month, DD, YYYY - [conv/abci] [Map LastBlockID.Hash to LastHeaderHash in conversion #303](https://github.com/celestiaorg/optimint/pull/303) [@tzdybal](https://github.com/tzdybal/) - [chore] [Fix multiple bugs for Ethermint #305](https://github.com/celestiaorg/optimint/pull/305) [@tzdybal](https://github.com/tzdybal/) - [lint] [Fix linter on main #308](https://github.com/celestiaorg/optimint/pull/308) [@tzdybal](https://github.com/tzdybal/) +- [rpc/client] [Make TestValidatorSetHandling stable](https://github.com/celestiaorg/optimint/pull/313) [@tzdybal](https://github.com/tzdybal/) - [go package] (Link to PR) Description @username diff --git a/rpc/client/client_test.go b/rpc/client/client_test.go index 69dcc4691c1..b63cf29c9b7 100644 --- a/rpc/client/client_test.go +++ b/rpc/client/client_test.go @@ -645,11 +645,15 @@ func TestValidatorSetHandling(t *testing.T) { pbValKey, err := encoding.PubKeyToProto(vKeys[0].PubKey()) require.NoError(err) + waitCh := make(chan interface{}) + app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Times(5) app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{{PubKey: pbValKey, Power: 0}}}).Once() app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Once() app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{{PubKey: pbValKey, Power: 100}}}).Once() - app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}) + app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Run(func(args mock.Arguments) { + waitCh <- nil + }) node, err := node.NewNode(context.Background(), config.NodeConfig{DALayer: "mock", Aggregator: true, BlockManagerConfig: config.BlockManagerConfig{BlockTime: 10 * time.Millisecond}}, key, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger()) require.NoError(err) @@ -673,7 +677,7 @@ func TestValidatorSetHandling(t *testing.T) { assert.Greater(vals.BlockHeight, lastHeight) lastHeight = vals.BlockHeight } - time.Sleep(100 * time.Millisecond) + <-waitCh // 6th EndBlock removes first validator from the list for h := int64(7); h <= 8; h++ { @@ -687,6 +691,7 @@ func TestValidatorSetHandling(t *testing.T) { // 8th EndBlock adds validator back for h := int64(9); h < 12; h++ { + <-waitCh vals, err := rpc.Validators(context.Background(), &h, nil, nil) assert.NoError(err) assert.NotNil(vals)