mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 04:55:18 +00:00
This change has two main effects: 1. Remove most of the Async methods from the abci.Client interface. Remaining are FlushAsync, CommitTxAsync, and DeliverTxAsync. 2. Rename the synchronous methods to remove the "Sync" suffix. The rest of the change is updating the implementations, subsets, and mocks of the interface, along with the call sites that point to them. * Fix stringly-typed mock stubs. * Rename helper method.
83 lines
1.8 KiB
Go
83 lines
1.8 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.TestingLogger()
|
|
|
|
_, c := setupClientServer(ctx, t, logger, app)
|
|
|
|
resp := make(chan error, 1)
|
|
go func() {
|
|
rsp, err := c.BeginBlock(ctx, types.RequestBeginBlock{})
|
|
assert.NoError(t, err)
|
|
assert.NoError(t, c.Flush(ctx))
|
|
assert.NotNil(t, rsp)
|
|
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) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
|
|
time.Sleep(200 * time.Millisecond)
|
|
return types.ResponseBeginBlock{}
|
|
}
|