agent_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package trace
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. )
  7. func TestStartAgent(t *testing.T) {
  8. logx.Disable()
  9. const (
  10. endpoint1 = "localhost:1234"
  11. endpoint2 = "remotehost:1234"
  12. endpoint3 = "localhost:1235"
  13. endpoint4 = "localhost:1236"
  14. agentHost1 = "localhost"
  15. agentPort1 = "6831"
  16. )
  17. c1 := Config{
  18. Name: "foo",
  19. }
  20. c2 := Config{
  21. Name: "bar",
  22. Endpoint: endpoint1,
  23. Batcher: kindJaeger,
  24. }
  25. c3 := Config{
  26. Name: "any",
  27. Endpoint: endpoint2,
  28. Batcher: kindZipkin,
  29. }
  30. c4 := Config{
  31. Name: "bla",
  32. Endpoint: endpoint3,
  33. Batcher: "otlp",
  34. }
  35. c5 := Config{
  36. Name: "grpc",
  37. Endpoint: endpoint3,
  38. Batcher: kindOtlpGrpc,
  39. }
  40. c6 := Config{
  41. Name: "otlphttp",
  42. Endpoint: endpoint4,
  43. Batcher: kindOtlpHttp,
  44. }
  45. c7 := Config{
  46. Name: "jaegerUDP",
  47. AgentHost: agentHost1,
  48. AgentPort: agentPort1,
  49. Batcher: kindJaeger,
  50. }
  51. c8 := Config{
  52. Name: "jaegerUDP",
  53. AgentHost: agentHost1,
  54. AgentPort: agentPort1,
  55. Endpoint: endpoint1,
  56. Batcher: kindJaeger,
  57. }
  58. StartAgent(c1)
  59. StartAgent(c1)
  60. StartAgent(c2)
  61. StartAgent(c3)
  62. StartAgent(c4)
  63. StartAgent(c5)
  64. StartAgent(c6)
  65. StartAgent(c7)
  66. StartAgent(c8)
  67. lock.Lock()
  68. defer lock.Unlock()
  69. // because remotehost cannot be resolved
  70. assert.Equal(t, 5, len(agents))
  71. _, ok := agents[""]
  72. assert.True(t, ok)
  73. _, ok = agents[endpoint1]
  74. assert.True(t, ok)
  75. _, ok = agents[endpoint2]
  76. assert.False(t, ok)
  77. _, ok = agents[c2.getEndpoint()]
  78. assert.True(t, ok)
  79. _, ok = agents[c3.getEndpoint()]
  80. assert.False(t, ok)
  81. _, ok = agents[c7.getEndpoint()]
  82. assert.True(t, ok)
  83. _, ok = agents[c8.getEndpoint()]
  84. assert.True(t, ok)
  85. }