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.

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