2015-10-19 12:34:53 -04:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-01-12 15:53:32 -05:00
|
|
|
abcicli "github.com/tendermint/abci/client"
|
|
|
|
"github.com/tendermint/abci/example/dummy"
|
|
|
|
"github.com/tendermint/abci/server"
|
|
|
|
"github.com/tendermint/abci/types"
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn "github.com/tendermint/tmlibs/common"
|
2015-10-19 12:34:53 -04:00
|
|
|
)
|
|
|
|
|
2016-08-17 22:28:08 -04:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
type AppConnTest interface {
|
2017-01-12 15:53:32 -05:00
|
|
|
EchoAsync(string) *abcicli.ReqRes
|
2016-08-17 22:28:08 -04:00
|
|
|
FlushSync() error
|
2017-01-12 15:13:47 -05:00
|
|
|
InfoSync() (types.ResponseInfo, error)
|
2016-08-17 22:28:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type appConnTest struct {
|
2017-01-12 15:53:32 -05:00
|
|
|
appConn abcicli.Client
|
2016-08-17 22:28:08 -04:00
|
|
|
}
|
|
|
|
|
2017-01-12 15:53:32 -05:00
|
|
|
func NewAppConnTest(appConn abcicli.Client) AppConnTest {
|
2016-08-17 22:28:08 -04:00
|
|
|
return &appConnTest{appConn}
|
|
|
|
}
|
|
|
|
|
2017-01-12 15:53:32 -05:00
|
|
|
func (app *appConnTest) EchoAsync(msg string) *abcicli.ReqRes {
|
2016-08-17 22:28:08 -04:00
|
|
|
return app.appConn.EchoAsync(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *appConnTest) FlushSync() error {
|
|
|
|
return app.appConn.FlushSync()
|
|
|
|
}
|
|
|
|
|
2017-01-12 15:13:47 -05:00
|
|
|
func (app *appConnTest) InfoSync() (types.ResponseInfo, error) {
|
2016-08-17 22:28:08 -04:00
|
|
|
return app.appConn.InfoSync()
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
2016-05-23 14:36:00 -04:00
|
|
|
var SOCKET = "socket"
|
|
|
|
|
2015-10-19 12:34:53 -04:00
|
|
|
func TestEcho(t *testing.T) {
|
2017-04-25 14:50:20 -04:00
|
|
|
sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6))
|
2016-09-10 17:14:55 -04:00
|
|
|
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
2016-02-08 00:48:58 -08:00
|
|
|
|
|
|
|
// Start server
|
2016-05-23 14:36:00 -04:00
|
|
|
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
2015-10-19 12:34:53 -04:00
|
|
|
if err != nil {
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn.Exit(err.Error())
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
2016-02-21 23:45:10 -08:00
|
|
|
defer s.Stop()
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start client
|
2017-01-12 15:53:32 -05:00
|
|
|
cli, err := clientCreator.NewABCIClient()
|
2015-10-19 12:34:53 -04:00
|
|
|
if err != nil {
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn.Exit(err.Error())
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
2016-08-17 22:28:08 -04:00
|
|
|
proxy := NewAppConnTest(cli)
|
|
|
|
t.Log("Connected")
|
2015-10-19 12:34:53 -04:00
|
|
|
|
|
|
|
for i := 0; i < 1000; i++ {
|
2017-04-25 14:50:20 -04:00
|
|
|
proxy.EchoAsync(cmn.Fmt("echo-%v", i))
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
|
|
|
proxy.FlushSync()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkEcho(b *testing.B) {
|
|
|
|
b.StopTimer() // Initialize
|
2017-04-25 14:50:20 -04:00
|
|
|
sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6))
|
2016-09-10 17:14:55 -04:00
|
|
|
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start server
|
2016-05-23 14:36:00 -04:00
|
|
|
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
2015-10-19 12:34:53 -04:00
|
|
|
if err != nil {
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn.Exit(err.Error())
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
2016-02-21 23:45:10 -08:00
|
|
|
defer s.Stop()
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start client
|
2017-01-12 15:53:32 -05:00
|
|
|
cli, err := clientCreator.NewABCIClient()
|
2015-10-19 12:34:53 -04:00
|
|
|
if err != nil {
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn.Exit(err.Error())
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
2016-08-17 22:28:08 -04:00
|
|
|
proxy := NewAppConnTest(cli)
|
|
|
|
b.Log("Connected")
|
2015-10-19 12:34:53 -04:00
|
|
|
echoString := strings.Repeat(" ", 200)
|
|
|
|
b.StartTimer() // Start benchmarking tests
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
proxy.EchoAsync(echoString)
|
|
|
|
}
|
|
|
|
proxy.FlushSync()
|
|
|
|
|
|
|
|
b.StopTimer()
|
|
|
|
// info := proxy.InfoSync()
|
|
|
|
//b.Log("N: ", b.N, info)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInfo(t *testing.T) {
|
2017-04-25 14:50:20 -04:00
|
|
|
sockPath := cmn.Fmt("unix:///tmp/echo_%v.sock", cmn.RandStr(6))
|
2016-09-10 17:14:55 -04:00
|
|
|
clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start server
|
2016-05-23 14:36:00 -04:00
|
|
|
s, err := server.NewSocketServer(sockPath, dummy.NewDummyApplication())
|
2015-10-19 12:34:53 -04:00
|
|
|
if err != nil {
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn.Exit(err.Error())
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
2016-02-21 23:45:10 -08:00
|
|
|
defer s.Stop()
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start client
|
2017-01-12 15:53:32 -05:00
|
|
|
cli, err := clientCreator.NewABCIClient()
|
2015-10-19 12:34:53 -04:00
|
|
|
if err != nil {
|
2017-04-25 14:50:20 -04:00
|
|
|
cmn.Exit(err.Error())
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
2016-08-17 22:28:08 -04:00
|
|
|
proxy := NewAppConnTest(cli)
|
|
|
|
t.Log("Connected")
|
|
|
|
|
2017-01-12 15:13:47 -05:00
|
|
|
resInfo, err := proxy.InfoSync()
|
|
|
|
if err != nil {
|
2015-12-01 20:12:01 -08:00
|
|
|
t.Errorf("Unexpected error: %v", err)
|
|
|
|
}
|
2017-01-12 15:13:47 -05:00
|
|
|
if string(resInfo.Data) != "{\"size\":0}" {
|
2016-12-06 04:04:08 -08:00
|
|
|
t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
|
2015-10-19 12:34:53 -04:00
|
|
|
}
|
|
|
|
}
|