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.

165 lines
4.2 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. t.Cleanup(func() {
  46. if err := s.Stop(); err != nil {
  47. t.Error(err)
  48. }
  49. })
  50. // Start client
  51. cli, err := clientCreator.NewABCIClient()
  52. if err != nil {
  53. t.Fatalf("Error creating ABCI client: %v", err.Error())
  54. }
  55. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  56. if err := cli.Start(); err != nil {
  57. t.Fatalf("Error starting ABCI client: %v", err.Error())
  58. }
  59. proxy := NewAppConnTest(cli)
  60. t.Log("Connected")
  61. for i := 0; i < 1000; i++ {
  62. proxy.EchoAsync(fmt.Sprintf("echo-%v", i))
  63. }
  64. if err := proxy.FlushSync(); err != nil {
  65. t.Error(err)
  66. }
  67. }
  68. func BenchmarkEcho(b *testing.B) {
  69. b.StopTimer() // Initialize
  70. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  71. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  72. // Start server
  73. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  74. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  75. if err := s.Start(); err != nil {
  76. b.Fatalf("Error starting socket server: %v", err.Error())
  77. }
  78. b.Cleanup(func() {
  79. if err := s.Stop(); err != nil {
  80. b.Error(err)
  81. }
  82. })
  83. // Start client
  84. cli, err := clientCreator.NewABCIClient()
  85. if err != nil {
  86. b.Fatalf("Error creating ABCI client: %v", err.Error())
  87. }
  88. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  89. if err := cli.Start(); err != nil {
  90. b.Fatalf("Error starting ABCI client: %v", err.Error())
  91. }
  92. proxy := NewAppConnTest(cli)
  93. b.Log("Connected")
  94. echoString := strings.Repeat(" ", 200)
  95. b.StartTimer() // Start benchmarking tests
  96. for i := 0; i < b.N; i++ {
  97. proxy.EchoAsync(echoString)
  98. }
  99. if err := proxy.FlushSync(); err != nil {
  100. b.Error(err)
  101. }
  102. b.StopTimer()
  103. // info := proxy.InfoSync(types.RequestInfo{""})
  104. //b.Log("N: ", b.N, info)
  105. }
  106. func TestInfo(t *testing.T) {
  107. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  108. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  109. // Start server
  110. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  111. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  112. if err := s.Start(); err != nil {
  113. t.Fatalf("Error starting socket server: %v", err.Error())
  114. }
  115. t.Cleanup(func() {
  116. if err := s.Stop(); err != nil {
  117. t.Error(err)
  118. }
  119. })
  120. // Start client
  121. cli, err := clientCreator.NewABCIClient()
  122. if err != nil {
  123. t.Fatalf("Error creating ABCI client: %v", err.Error())
  124. }
  125. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  126. if err := cli.Start(); err != nil {
  127. t.Fatalf("Error starting ABCI client: %v", err.Error())
  128. }
  129. proxy := NewAppConnTest(cli)
  130. t.Log("Connected")
  131. resInfo, err := proxy.InfoSync(RequestInfo)
  132. if err != nil {
  133. t.Errorf("unexpected error: %v", err)
  134. }
  135. if resInfo.Data != "{\"size\":0}" {
  136. t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
  137. }
  138. }