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.

87 lines
1.8 KiB

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