unwind client creator

This commit is contained in:
tycho garen
2022-03-04 15:23:08 -05:00
parent fa1520dd90
commit 21f93fa15e
13 changed files with 63 additions and 80 deletions
+18 -18
View File
@@ -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)
+2 -13
View File
@@ -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)