2015-10-19 09:34:53 -07:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/tendermint/go-common"
|
2016-02-14 15:03:55 -08:00
|
|
|
"github.com/tendermint/tmsp/example/dummy"
|
2015-10-19 09:34:53 -07:00
|
|
|
"github.com/tendermint/tmsp/server"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEcho(t *testing.T) {
|
|
|
|
sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
|
2016-02-08 00:48:58 -08:00
|
|
|
|
|
|
|
// Start server
|
2016-02-21 23:45:10 -08:00
|
|
|
s, err := server.NewServer(sockPath, dummy.NewDummyApplication())
|
2015-10-19 09:34:53 -07:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
}
|
2016-02-21 23:45:10 -08:00
|
|
|
defer s.Stop()
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start client
|
|
|
|
proxy, err := NewRemoteAppConn(sockPath)
|
2015-10-19 09:34:53 -07:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
} else {
|
|
|
|
t.Log("Connected")
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
proxy.EchoAsync(Fmt("echo-%v", i))
|
|
|
|
}
|
|
|
|
proxy.FlushSync()
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkEcho(b *testing.B) {
|
|
|
|
b.StopTimer() // Initialize
|
|
|
|
sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start server
|
2016-02-21 23:45:10 -08:00
|
|
|
s, err := server.NewServer(sockPath, dummy.NewDummyApplication())
|
2015-10-19 09:34:53 -07:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
}
|
2016-02-21 23:45:10 -08:00
|
|
|
defer s.Stop()
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start client
|
|
|
|
proxy, err := NewRemoteAppConn(sockPath)
|
2015-10-19 09:34:53 -07:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
} else {
|
|
|
|
b.Log("Connected")
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start server
|
2016-02-21 23:45:10 -08:00
|
|
|
s, err := server.NewServer(sockPath, dummy.NewDummyApplication())
|
2015-10-19 09:34:53 -07:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
}
|
2016-02-21 23:45:10 -08:00
|
|
|
defer s.Stop()
|
2016-02-08 00:48:58 -08:00
|
|
|
// Start client
|
|
|
|
proxy, err := NewRemoteAppConn(sockPath)
|
2015-10-19 09:34:53 -07:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
} else {
|
|
|
|
t.Log("Connected")
|
|
|
|
}
|
|
|
|
proxy.Start()
|
2015-12-01 20:12:01 -08:00
|
|
|
data, err := proxy.InfoSync()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error: %v", err)
|
|
|
|
}
|
2016-01-25 14:34:08 -08:00
|
|
|
if data != "size:0" {
|
2015-10-19 09:34:53 -07:00
|
|
|
t.Error("Expected ResponseInfo with one element 'size:0' but got something else")
|
|
|
|
}
|
|
|
|
}
|