agent_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. )
  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: "otlpgrpc",
  37. Endpoint: endpoint3,
  38. Batcher: kindOtlpGrpc,
  39. OtlpHeaders: map[string]string{
  40. "uptrace-dsn": "http://project2_secret_token@localhost:14317/2",
  41. },
  42. }
  43. c6 := Config{
  44. Name: "otlphttp",
  45. Endpoint: endpoint4,
  46. Batcher: kindOtlpHttp,
  47. OtlpHeaders: map[string]string{
  48. "uptrace-dsn": "http://project2_secret_token@localhost:14318/2",
  49. },
  50. OtlpHttpPath: "/v1/traces",
  51. }
  52. c7 := Config{
  53. Name: "UDP",
  54. Endpoint: endpoint5,
  55. Batcher: kindJaeger,
  56. }
  57. c8 := Config{
  58. Disabled: true,
  59. Endpoint: endpoint6,
  60. Batcher: kindJaeger,
  61. }
  62. StartAgent(c1)
  63. StartAgent(c1)
  64. StartAgent(c2)
  65. StartAgent(c3)
  66. StartAgent(c4)
  67. StartAgent(c5)
  68. StartAgent(c6)
  69. StartAgent(c7)
  70. StartAgent(c8)
  71. defer StopAgent()
  72. lock.Lock()
  73. defer lock.Unlock()
  74. // because remotehost cannot be resolved
  75. assert.Equal(t, 5, len(agents))
  76. _, ok := agents[""]
  77. assert.True(t, ok)
  78. _, ok = agents[endpoint1]
  79. assert.True(t, ok)
  80. _, ok = agents[endpoint2]
  81. assert.False(t, ok)
  82. _, ok = agents[endpoint5]
  83. assert.True(t, ok)
  84. _, ok = agents[endpoint6]
  85. assert.False(t, ok)
  86. }