mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 22:44:24 +00:00
unwind client creator
This commit is contained in:
@@ -51,7 +51,10 @@ var SOCKET = "socket"
|
||||
func TestEcho(t *testing.T) {
|
||||
sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
|
||||
logger := log.TestingLogger()
|
||||
clientCreator := abciclient.NewRemoteCreator(logger, sockPath, SOCKET, true)
|
||||
client, err := abciclient.NewClient(logger, sockPath, SOCKET, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -62,12 +65,9 @@ func TestEcho(t *testing.T) {
|
||||
t.Cleanup(func() { cancel(); s.Wait() })
|
||||
|
||||
// Start client
|
||||
cli, err := clientCreator(logger.With("module", "abci-client"))
|
||||
require.NoError(t, err, "Error creating ABCI client:")
|
||||
require.NoError(t, client.Start(ctx), "Error starting ABCI client")
|
||||
|
||||
require.NoError(t, cli.Start(ctx), "Error starting ABCI client")
|
||||
|
||||
proxy := newAppConnTest(cli)
|
||||
proxy := newAppConnTest(client)
|
||||
t.Log("Connected")
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
@@ -91,7 +91,10 @@ func BenchmarkEcho(b *testing.B) {
|
||||
b.StopTimer() // Initialize
|
||||
sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
|
||||
logger := log.TestingLogger()
|
||||
clientCreator := abciclient.NewRemoteCreator(logger, sockPath, SOCKET, true)
|
||||
client, err := abciclient.NewClient(logger, sockPath, SOCKET, true)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -102,12 +105,9 @@ func BenchmarkEcho(b *testing.B) {
|
||||
b.Cleanup(func() { cancel(); s.Wait() })
|
||||
|
||||
// Start client
|
||||
cli, err := clientCreator(logger.With("module", "abci-client"))
|
||||
require.NoError(b, err, "Error creating ABCI client")
|
||||
require.NoError(b, client.Start(ctx), "Error starting ABCI client")
|
||||
|
||||
require.NoError(b, cli.Start(ctx), "Error starting ABCI client")
|
||||
|
||||
proxy := newAppConnTest(cli)
|
||||
proxy := newAppConnTest(client)
|
||||
b.Log("Connected")
|
||||
echoString := strings.Repeat(" ", 200)
|
||||
b.StartTimer() // Start benchmarking tests
|
||||
@@ -139,7 +139,10 @@ func TestInfo(t *testing.T) {
|
||||
|
||||
sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
|
||||
logger := log.TestingLogger()
|
||||
clientCreator := abciclient.NewRemoteCreator(logger, sockPath, SOCKET, true)
|
||||
client, err := abciclient.NewClient(logger, sockPath, SOCKET, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Start server
|
||||
s := server.NewSocketServer(logger.With("module", "abci-server"), sockPath, kvstore.NewApplication())
|
||||
@@ -147,12 +150,9 @@ func TestInfo(t *testing.T) {
|
||||
t.Cleanup(func() { cancel(); s.Wait() })
|
||||
|
||||
// Start client
|
||||
cli, err := clientCreator(logger.With("module", "abci-client"))
|
||||
require.NoError(t, err, "Error creating ABCI client")
|
||||
require.NoError(t, client.Start(ctx), "Error starting ABCI client")
|
||||
|
||||
require.NoError(t, cli.Start(ctx), "Error starting ABCI client")
|
||||
|
||||
proxy := newAppConnTest(cli)
|
||||
proxy := newAppConnTest(client)
|
||||
t.Log("Connected")
|
||||
|
||||
resInfo, err := proxy.Info(ctx, RequestInfo)
|
||||
|
||||
@@ -36,13 +36,7 @@ func TestAppConns_Start_Stop(t *testing.T) {
|
||||
clientMock.On("Wait").Return(nil).Times(1)
|
||||
cl := &noopStoppableClientImpl{Client: clientMock}
|
||||
|
||||
creatorCallCount := 0
|
||||
creator := func(logger log.Logger) (abciclient.Client, error) {
|
||||
creatorCallCount++
|
||||
return cl, nil
|
||||
}
|
||||
|
||||
appConns := New(creator, log.TestingLogger(), NopMetrics())
|
||||
appConns := New(cl, log.TestingLogger(), NopMetrics())
|
||||
|
||||
err := appConns.Start(ctx)
|
||||
require.NoError(t, err)
|
||||
@@ -54,7 +48,6 @@ func TestAppConns_Start_Stop(t *testing.T) {
|
||||
|
||||
clientMock.AssertExpectations(t)
|
||||
assert.Equal(t, 1, cl.count)
|
||||
assert.Equal(t, 1, creatorCallCount)
|
||||
}
|
||||
|
||||
// Upon failure, we call tmos.Kill
|
||||
@@ -80,11 +73,7 @@ func TestAppConns_Failure(t *testing.T) {
|
||||
clientMock.On("Error").Return(errors.New("EOF"))
|
||||
cl := &noopStoppableClientImpl{Client: clientMock}
|
||||
|
||||
creator := func(log.Logger) (abciclient.Client, error) {
|
||||
return cl, nil
|
||||
}
|
||||
|
||||
appConns := New(creator, log.TestingLogger(), NopMetrics())
|
||||
appConns := New(cl, log.TestingLogger(), NopMetrics())
|
||||
|
||||
err := appConns.Start(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user