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.

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