mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 15:07:24 +00:00
* Rebased and git-squashed the commits in PR #6546 migrate abci to finalizeBlock work on abci, proxy and mempool abciresponse, blok events, indexer, some tests fix some tests fix errors fix errors in abci fix tests amd errors * Fixes after rebasing PR#6546 * Restored height to RequestFinalizeBlock & other * Fixed more UTs * Fixed kvstore * More UT fixes * last TC fixed * make format * Update internal/consensus/mempool_test.go Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com> * Addressed @williambanfield's comments * Fixed UTs * Addressed last comments from @williambanfield * make format Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package abciclient_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"math/rand"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
abciclient "github.com/tendermint/tendermint/abci/client"
|
|
"github.com/tendermint/tendermint/abci/server"
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
"github.com/tendermint/tendermint/libs/service"
|
|
)
|
|
|
|
func TestProperSyncCalls(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
app := slowApp{}
|
|
logger := log.NewNopLogger()
|
|
|
|
_, c := setupClientServer(ctx, t, logger, app)
|
|
|
|
resp := make(chan error, 1)
|
|
go func() {
|
|
rsp, err := c.FinalizeBlock(ctx, types.RequestFinalizeBlock{})
|
|
assert.NoError(t, err)
|
|
assert.NoError(t, c.Flush(ctx))
|
|
assert.NotNil(t, rsp)
|
|
select {
|
|
case <-ctx.Done():
|
|
case resp <- c.Error():
|
|
}
|
|
}()
|
|
|
|
select {
|
|
case <-time.After(time.Second):
|
|
require.Fail(t, "No response arrived")
|
|
case err, ok := <-resp:
|
|
require.True(t, ok, "Must not close channel")
|
|
assert.NoError(t, err, "This should return success")
|
|
}
|
|
}
|
|
|
|
func setupClientServer(
|
|
ctx context.Context,
|
|
t *testing.T,
|
|
logger log.Logger,
|
|
app types.Application,
|
|
) (service.Service, abciclient.Client) {
|
|
t.Helper()
|
|
|
|
// some port between 20k and 30k
|
|
port := 20000 + rand.Int31()%10000
|
|
addr := fmt.Sprintf("localhost:%d", port)
|
|
|
|
s, err := server.NewServer(logger, addr, "socket", app)
|
|
require.NoError(t, err)
|
|
require.NoError(t, s.Start(ctx))
|
|
t.Cleanup(s.Wait)
|
|
|
|
c := abciclient.NewSocketClient(logger, addr, true)
|
|
require.NoError(t, c.Start(ctx))
|
|
t.Cleanup(c.Wait)
|
|
|
|
require.True(t, s.IsRunning())
|
|
require.True(t, c.IsRunning())
|
|
|
|
return s, c
|
|
}
|
|
|
|
type slowApp struct {
|
|
types.BaseApplication
|
|
}
|
|
|
|
func (slowApp) FinalizeBlock(req types.RequestFinalizeBlock) types.ResponseFinalizeBlock {
|
|
time.Sleep(200 * time.Millisecond)
|
|
return types.ResponseFinalizeBlock{}
|
|
}
|