agent_test.go 1.9 KB

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