client_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package client
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/service/main/seq-server/model"
  7. )
  8. func TestDynamic(t *testing.T) {
  9. s := New2(nil)
  10. time.Sleep(5 * time.Second)
  11. testID(t, s)
  12. testID32(t, s)
  13. }
  14. func testID(t *testing.T, s *Service2) {
  15. res := make(map[int64]struct{})
  16. for i := 0; i < 10000; i++ {
  17. id, err := s.ID(context.TODO(), &model.ArgBusiness{BusinessID: 7, Token: "RA8yy0RjDCBTGgFUha4hPOnhxfXvM8hR"})
  18. if err != nil {
  19. t.Errorf("s.ID error(%v)", err)
  20. continue
  21. }
  22. if _, ok := res[id]; ok {
  23. t.Errorf("s.ID repeat id:%d", id)
  24. t.FailNow()
  25. }
  26. res[id] = struct{}{}
  27. t.Logf("got ID(%d)", id)
  28. }
  29. }
  30. func testID32(t *testing.T, s *Service2) {
  31. res := make(map[int32]struct{})
  32. for i := 0; i < 10000; i++ {
  33. id, err := s.ID32(context.TODO(), &model.ArgBusiness{BusinessID: 7, Token: "RA8yy0RjDCBTGgFUha4hPOnhxfXvM8hR"})
  34. if err != nil {
  35. t.Errorf("s.ID error(%v)", err)
  36. continue
  37. }
  38. if _, ok := res[id]; ok {
  39. t.Errorf("s.ID repeat id:%d", id)
  40. t.FailNow()
  41. }
  42. res[id] = struct{}{}
  43. t.Logf("got ID(%d)", id)
  44. }
  45. }