agent_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package trace
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/wuntsong-org/go-zero-plus/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. endpoint5 = "udp://localhost:6831"
  15. endpoint6 = "localhost:1237"
  16. endpoint71 = "/tmp/trace.log"
  17. endpoint72 = "/not-exist-fs/trace.log"
  18. )
  19. c1 := Config{
  20. Name: "foo",
  21. }
  22. c2 := Config{
  23. Name: "bar",
  24. Endpoint: endpoint1,
  25. Batcher: kindJaeger,
  26. }
  27. c3 := Config{
  28. Name: "any",
  29. Endpoint: endpoint2,
  30. Batcher: kindZipkin,
  31. }
  32. c4 := Config{
  33. Name: "bla",
  34. Endpoint: endpoint3,
  35. Batcher: "otlp",
  36. }
  37. c5 := Config{
  38. Name: "otlpgrpc",
  39. Endpoint: endpoint3,
  40. Batcher: kindOtlpGrpc,
  41. OtlpHeaders: map[string]string{
  42. "uptrace-dsn": "http://project2_secret_token@localhost:14317/2",
  43. },
  44. }
  45. c6 := Config{
  46. Name: "otlphttp",
  47. Endpoint: endpoint4,
  48. Batcher: kindOtlpHttp,
  49. OtlpHeaders: map[string]string{
  50. "uptrace-dsn": "http://project2_secret_token@localhost:14318/2",
  51. },
  52. OtlpHttpPath: "/v1/traces",
  53. }
  54. c7 := Config{
  55. Name: "UDP",
  56. Endpoint: endpoint5,
  57. Batcher: kindJaeger,
  58. }
  59. c8 := Config{
  60. Disabled: true,
  61. Endpoint: endpoint6,
  62. Batcher: kindJaeger,
  63. }
  64. c9 := Config{
  65. Name: "file",
  66. Endpoint: endpoint71,
  67. Batcher: kindFile,
  68. }
  69. c10 := Config{
  70. Name: "file",
  71. Endpoint: endpoint72,
  72. Batcher: kindFile,
  73. }
  74. StartAgent(c1)
  75. StartAgent(c1)
  76. StartAgent(c2)
  77. StartAgent(c3)
  78. StartAgent(c4)
  79. StartAgent(c5)
  80. StartAgent(c6)
  81. StartAgent(c7)
  82. StartAgent(c8)
  83. StartAgent(c9)
  84. StartAgent(c10)
  85. defer StopAgent()
  86. lock.Lock()
  87. defer lock.Unlock()
  88. // because remotehost cannot be resolved
  89. assert.Equal(t, 6, len(agents))
  90. _, ok := agents[""]
  91. assert.True(t, ok)
  92. _, ok = agents[endpoint1]
  93. assert.True(t, ok)
  94. _, ok = agents[endpoint2]
  95. assert.False(t, ok)
  96. _, ok = agents[endpoint5]
  97. assert.True(t, ok)
  98. _, ok = agents[endpoint6]
  99. assert.False(t, ok)
  100. _, ok = agents[endpoint71]
  101. assert.True(t, ok)
  102. _, ok = agents[endpoint72]
  103. assert.False(t, ok)
  104. }