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.

98 lines
2.1 KiB

  1. package proxy
  2. import (
  3. "bytes"
  4. "strings"
  5. "testing"
  6. . "github.com/tendermint/go-common"
  7. "github.com/tendermint/go-logio"
  8. example "github.com/tendermint/tmsp/example"
  9. "github.com/tendermint/tmsp/server"
  10. )
  11. func TestEcho(t *testing.T) {
  12. sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
  13. _, err := server.StartListener(sockPath, example.NewDummyApplication())
  14. if err != nil {
  15. Exit(err.Error())
  16. }
  17. conn, err := Connect(sockPath)
  18. if err != nil {
  19. Exit(err.Error())
  20. } else {
  21. t.Log("Connected")
  22. }
  23. logBuffer := bytes.NewBuffer(nil)
  24. logConn := logio.NewLoggedConn(conn, logBuffer)
  25. proxy := NewRemoteAppContext(logConn, 10)
  26. proxy.SetResponseCallback(nil)
  27. proxy.Start()
  28. for i := 0; i < 1000; i++ {
  29. proxy.EchoAsync(Fmt("echo-%v", i))
  30. }
  31. proxy.FlushSync()
  32. /*
  33. if t.Failed() {
  34. logio.PrintReader(logBuffer)
  35. }
  36. */
  37. }
  38. func BenchmarkEcho(b *testing.B) {
  39. b.StopTimer() // Initialize
  40. sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
  41. _, err := server.StartListener(sockPath, example.NewDummyApplication())
  42. if err != nil {
  43. Exit(err.Error())
  44. }
  45. conn, err := Connect(sockPath)
  46. if err != nil {
  47. Exit(err.Error())
  48. } else {
  49. b.Log("Connected")
  50. }
  51. proxy := NewRemoteAppContext(conn, 10)
  52. proxy.Start()
  53. echoString := strings.Repeat(" ", 200)
  54. b.StartTimer() // Start benchmarking tests
  55. for i := 0; i < b.N; i++ {
  56. proxy.EchoAsync(echoString)
  57. }
  58. proxy.FlushSync()
  59. b.StopTimer()
  60. // info := proxy.InfoSync()
  61. //b.Log("N: ", b.N, info)
  62. }
  63. func TestInfo(t *testing.T) {
  64. sockPath := Fmt("unix:///tmp/echo_%v.sock", RandStr(6))
  65. _, err := server.StartListener(sockPath, example.NewDummyApplication())
  66. if err != nil {
  67. Exit(err.Error())
  68. }
  69. conn, err := Connect(sockPath)
  70. if err != nil {
  71. Exit(err.Error())
  72. } else {
  73. t.Log("Connected")
  74. }
  75. logBuffer := bytes.NewBuffer(nil)
  76. logConn := logio.NewLoggedConn(conn, logBuffer)
  77. proxy := NewRemoteAppContext(logConn, 10)
  78. proxy.Start()
  79. data, err := proxy.InfoSync()
  80. if err != nil {
  81. t.Errorf("Unexpected error: %v", err)
  82. }
  83. if data[0] != "size:0" {
  84. t.Error("Expected ResponseInfo with one element 'size:0' but got something else")
  85. }
  86. }