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.

186 lines
4.8 KiB

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. "context"
  4. "fmt"
  5. "strings"
  6. "testing"
  7. abcicli "github.com/tendermint/tendermint/abci/client"
  8. "github.com/tendermint/tendermint/abci/example/kvstore"
  9. "github.com/tendermint/tendermint/abci/server"
  10. "github.com/tendermint/tendermint/abci/types"
  11. "github.com/tendermint/tendermint/libs/log"
  12. tmrand "github.com/tendermint/tendermint/libs/rand"
  13. )
  14. //----------------------------------------
  15. type appConnTestI interface {
  16. EchoAsync(ctx context.Context, msg string) (*abcicli.ReqRes, error)
  17. FlushSync(context.Context) error
  18. InfoSync(context.Context, types.RequestInfo) (*types.ResponseInfo, error)
  19. }
  20. type appConnTest struct {
  21. appConn abcicli.Client
  22. }
  23. func newAppConnTest(appConn abcicli.Client) appConnTestI {
  24. return &appConnTest{appConn}
  25. }
  26. func (app *appConnTest) EchoAsync(ctx context.Context, msg string) (*abcicli.ReqRes, error) {
  27. return app.appConn.EchoAsync(ctx, msg)
  28. }
  29. func (app *appConnTest) FlushSync(ctx context.Context) error {
  30. return app.appConn.FlushSync(ctx)
  31. }
  32. func (app *appConnTest) InfoSync(ctx context.Context, req types.RequestInfo) (*types.ResponseInfo, error) {
  33. return app.appConn.InfoSync(ctx, req)
  34. }
  35. //----------------------------------------
  36. var SOCKET = "socket"
  37. func TestEcho(t *testing.T) {
  38. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  39. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  40. // Start server
  41. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  42. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  43. if err := s.Start(); err != nil {
  44. t.Fatalf("Error starting socket server: %v", err.Error())
  45. }
  46. t.Cleanup(func() {
  47. if err := s.Stop(); err != nil {
  48. t.Error(err)
  49. }
  50. })
  51. // Start client
  52. cli, err := clientCreator.NewABCIClient()
  53. if err != nil {
  54. t.Fatalf("Error creating ABCI client: %v", err.Error())
  55. }
  56. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  57. if err := cli.Start(); err != nil {
  58. t.Fatalf("Error starting ABCI client: %v", err.Error())
  59. }
  60. proxy := newAppConnTest(cli)
  61. t.Log("Connected")
  62. ctx := context.Background()
  63. for i := 0; i < 1000; i++ {
  64. _, err = proxy.EchoAsync(ctx, fmt.Sprintf("echo-%v", i))
  65. if err != nil {
  66. t.Error(err)
  67. }
  68. // flush sometimes
  69. if i%128 == 0 {
  70. if err := proxy.FlushSync(ctx); err != nil {
  71. t.Error(err)
  72. }
  73. }
  74. }
  75. if err := proxy.FlushSync(ctx); err != nil {
  76. t.Error(err)
  77. }
  78. }
  79. func BenchmarkEcho(b *testing.B) {
  80. b.StopTimer() // Initialize
  81. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  82. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  83. // Start server
  84. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  85. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  86. if err := s.Start(); err != nil {
  87. b.Fatalf("Error starting socket server: %v", err.Error())
  88. }
  89. b.Cleanup(func() {
  90. if err := s.Stop(); err != nil {
  91. b.Error(err)
  92. }
  93. })
  94. // Start client
  95. cli, err := clientCreator.NewABCIClient()
  96. if err != nil {
  97. b.Fatalf("Error creating ABCI client: %v", err.Error())
  98. }
  99. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  100. if err := cli.Start(); err != nil {
  101. b.Fatalf("Error starting ABCI client: %v", err.Error())
  102. }
  103. proxy := newAppConnTest(cli)
  104. b.Log("Connected")
  105. echoString := strings.Repeat(" ", 200)
  106. b.StartTimer() // Start benchmarking tests
  107. ctx := context.Background()
  108. for i := 0; i < b.N; i++ {
  109. _, err = proxy.EchoAsync(ctx, echoString)
  110. if err != nil {
  111. b.Error(err)
  112. }
  113. // flush sometimes
  114. if i%128 == 0 {
  115. if err := proxy.FlushSync(ctx); err != nil {
  116. b.Error(err)
  117. }
  118. }
  119. }
  120. if err := proxy.FlushSync(ctx); err != nil {
  121. b.Error(err)
  122. }
  123. b.StopTimer()
  124. // info := proxy.InfoSync(types.RequestInfo{""})
  125. // b.Log("N: ", b.N, info)
  126. }
  127. func TestInfo(t *testing.T) {
  128. sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6))
  129. clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true)
  130. // Start server
  131. s := server.NewSocketServer(sockPath, kvstore.NewApplication())
  132. s.SetLogger(log.TestingLogger().With("module", "abci-server"))
  133. if err := s.Start(); err != nil {
  134. t.Fatalf("Error starting socket server: %v", err.Error())
  135. }
  136. t.Cleanup(func() {
  137. if err := s.Stop(); err != nil {
  138. t.Error(err)
  139. }
  140. })
  141. // Start client
  142. cli, err := clientCreator.NewABCIClient()
  143. if err != nil {
  144. t.Fatalf("Error creating ABCI client: %v", err.Error())
  145. }
  146. cli.SetLogger(log.TestingLogger().With("module", "abci-client"))
  147. if err := cli.Start(); err != nil {
  148. t.Fatalf("Error starting ABCI client: %v", err.Error())
  149. }
  150. proxy := newAppConnTest(cli)
  151. t.Log("Connected")
  152. resInfo, err := proxy.InfoSync(context.Background(), RequestInfo)
  153. if err != nil {
  154. t.Errorf("unexpected error: %v", err)
  155. }
  156. if resInfo.Data != "{\"size\":0}" {
  157. t.Error("Expected ResponseInfo with one element '{\"size\":0}' but got something else")
  158. }
  159. }