You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.0 KiB

8 years ago
8 years ago
8 years ago
8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
8 years ago
  1. package proxy
  2. import (
  3. "fmt"
  4. "strings"
  5. "testing"
  6. abcicli "github.com/tendermint/tendermint/abci/client"
  7. "github.com/tendermint/tendermint/abci/example/kvstore"
  8. "github.com/tendermint/tendermint/abci/server"
  9. "github.com/tendermint/tendermint/abci/types"
  10. "github.com/tendermint/tendermint/libs/log"
  11. tmrand "github.com/tendermint/tendermint/libs/rand"
  12. )
  13. //----------------------------------------
  14. type AppConnTest interface {
  15. EchoAsync(string) *abcicli.ReqRes
  16. FlushSync() error
  17. InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
  18. }
  19. type appConnTest struct {
  20. appConn abcicli.Client
  21. }
  22. func NewAppConnTest(appConn abcicli.Client) AppConnTest {
  23. return &appConnTest{appConn}
  24. }
  25. func (app *appConnTest) EchoAsync(msg string) *abcicli.ReqRes {
  26. return app.appConn.EchoAsync(msg)
  27. }
  28. func (app *appConnTest) FlushSync() error {
  29. return app.appConn.FlushSync()
  30. }
  31. func (app *appConnTest) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
  32. return app.appConn.InfoSync(req)
  33. }
  34. //----------------------------------------
  35. var SOCKET = "socket"
  36. func TestEcho(t *testing.T) {
  37. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  38. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  39. // Start server
  40. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  41. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  42. if err := s.Start(); err != nil {
  43. t.Fatalf("Error starting socket server: %v", err.Error())
  44. }
  45. defer s.Stop()
  46. // Start client
  47. cli, err := clientCreator.NewABCIClient()
  48. if err != nil {
  49. t.Fatalf("Error creating ABCI client: %v", err.Error())
  50. }
  51. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  52. if err := cli.Start(); err != nil {
  53. t.Fatalf("Error starting ABCI client: %v", err.Error())
  54. }
  55. proxy := NewAppConnTest(cli)
  56. t.Log("Connected")
  57. for i := 0; i < 1000; i++ {
  58. proxy.EchoAsync(fmt.Sprintf("echo-%v", i))
  59. }
  60. if err := proxy.FlushSync(); err != nil {
  61. t.Error(err)
  62. }
  63. }
  64. func BenchmarkEcho(b *testing.B) {
  65. b.StopTimer() // Initialize
  66. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  67. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  68. // Start server
  69. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  70. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  71. if err := s.Start(); err != nil {
  72. b.Fatalf("Error starting socket server: %v", err.Error())
  73. }
  74. defer s.Stop()
  75. // Start client
  76. cli, err := clientCreator.NewABCIClient()
  77. if err != nil {
  78. b.Fatalf("Error creating ABCI client: %v", err.Error())
  79. }
  80. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  81. if err := cli.Start(); err != nil {
  82. b.Fatalf("Error starting ABCI client: %v", err.Error())
  83. }
  84. proxy := NewAppConnTest(cli)
  85. b.Log("Connected")
  86. echoString := strings.Repeat(" ", 200)
  87. b.StartTimer() // Start benchmarking tests
  88. for i := 0; i < b.N; i++ {
  89. proxy.EchoAsync(echoString)
  90. }
  91. if err := proxy.FlushSync(); err != nil {
  92. b.Error(err)
  93. }
  94. b.StopTimer()
  95. // info := proxy.InfoSync(types.RequestInfo{""})
  96. //b.Log("N: ", b.N, info)
  97. }
  98. func TestInfo(t *testing.T) {
  99. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  100. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  101. // Start server
  102. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  103. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  104. if err := s.Start(); err != nil {
  105. t.Fatalf("Error starting socket server: %v", err.Error())
  106. }
  107. defer s.Stop()
  108. // Start client
  109. cli, err := clientCreator.NewABCIClient()
  110. if err != nil {
  111. t.Fatalf("Error creating ABCI client: %v", err.Error())
  112. }
  113. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  114. if err := cli.Start(); err != nil {
  115. t.Fatalf("Error starting ABCI client: %v", err.Error())
  116. }
  117. proxy := NewAppConnTest(cli)
  118. t.Log("Connected")
  119. resInfo, err := proxy.InfoSync(RequestInfo)
  120. if err != nil {
  121. t.Errorf("unexpected error: %v", err)
  122. }
  123. if resInfo.Data != "{\"size\":0}" {
  124. t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
  125. }
  126. }