Skip to content

Commit 989fb16

Browse files
authored
fix: make TestValidatorSetHandling stable (cosmos#313)
Instead of `time.Sleep` a channel is used for reliable synchronization
1 parent 8b9271f commit 989fb16

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG-PENDING.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ Month, DD, YYYY
3838
- [conv/abci] [Map LastBlockID.Hash to LastHeaderHash in conversion #303](https://github.com/celestiaorg/optimint/pull/303) [@tzdybal](https://github.com/tzdybal/)
3939
- [chore] [Fix multiple bugs for Ethermint #305](https://github.com/celestiaorg/optimint/pull/305) [@tzdybal](https://github.com/tzdybal/)
4040
- [lint] [Fix linter on main #308](https://github.com/celestiaorg/optimint/pull/308) [@tzdybal](https://github.com/tzdybal/)
41+
- [rpc/client] [Make TestValidatorSetHandling stable](https://github.com/celestiaorg/optimint/pull/313) [@tzdybal](https://github.com/tzdybal/)
4142

4243
- [go package] (Link to PR) Description @username

rpc/client/client_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,15 @@ func TestValidatorSetHandling(t *testing.T) {
645645
pbValKey, err := encoding.PubKeyToProto(vKeys[0].PubKey())
646646
require.NoError(err)
647647

648+
waitCh := make(chan interface{})
649+
648650
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Times(5)
649651
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{{PubKey: pbValKey, Power: 0}}}).Once()
650652
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Once()
651653
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{{PubKey: pbValKey, Power: 100}}}).Once()
652-
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{})
654+
app.On("EndBlock", mock.Anything).Return(abci.ResponseEndBlock{}).Run(func(args mock.Arguments) {
655+
waitCh <- nil
656+
})
653657

654658
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())
655659
require.NoError(err)
@@ -673,7 +677,7 @@ func TestValidatorSetHandling(t *testing.T) {
673677
assert.Greater(vals.BlockHeight, lastHeight)
674678
lastHeight = vals.BlockHeight
675679
}
676-
time.Sleep(100 * time.Millisecond)
680+
<-waitCh
677681

678682
// 6th EndBlock removes first validator from the list
679683
for h := int64(7); h <= 8; h++ {
@@ -687,6 +691,7 @@ func TestValidatorSetHandling(t *testing.T) {
687691

688692
// 8th EndBlock adds validator back
689693
for h := int64(9); h < 12; h++ {
694+
<-waitCh
690695
vals, err := rpc.Validators(context.Background(), &h, nil, nil)
691696
assert.NoError(err)
692697
assert.NotNil(vals)

0 commit comments

Comments
 (0)