server_test.go 866 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package tcpcollect
  2. import (
  3. "context"
  4. "io"
  5. "net"
  6. "os"
  7. "testing"
  8. "time"
  9. "go-common/app/service/main/dapper/conf"
  10. "go-common/app/service/main/dapper/model"
  11. "go-common/app/service/main/dapper/pkg/process"
  12. )
  13. func TestCollect(t *testing.T) {
  14. count := 0
  15. collect := New(&conf.Collect{Network: "tcp", Addr: "127.0.0.1:6190"})
  16. collect.RegisterProcess(process.MockProcess(func(context.Context, *model.ProtoSpan) error {
  17. count++
  18. return nil
  19. }))
  20. if err := collect.Start(); err != nil {
  21. t.Fatal(err)
  22. }
  23. fp, err := os.Open("testdata/data.bin")
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. defer fp.Close()
  28. conn, err := net.Dial("tcp", "127.0.0.1:6190")
  29. if err != nil {
  30. t.Fatal(err)
  31. }
  32. defer conn.Close()
  33. _, err = io.Copy(conn, fp)
  34. if err != nil {
  35. t.Error(err)
  36. }
  37. time.Sleep(time.Second)
  38. if count <= 0 {
  39. t.Errorf("expect more than one span write")
  40. }
  41. }