service_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/job/main/click/conf"
  9. "go-common/app/job/main/click/model"
  10. "go-common/library/sync/errgroup"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var (
  14. s *Service
  15. )
  16. func init() {
  17. dir, _ := filepath.Abs("../cmd/click-job-test.toml")
  18. flag.Set("conf", dir)
  19. conf.Init()
  20. s = New(conf.Conf)
  21. }
  22. func Test_Archive(t *testing.T) {
  23. Convey("isReplay test", t, func() {
  24. b := s.isReplay(context.TODO(), 1, 1, "", 1)
  25. So(b, ShouldBeFalse)
  26. })
  27. return
  28. }
  29. func Test_SetSpecial(t *testing.T) {
  30. Convey("SetSpecial", t, func() {
  31. s.SetSpecial(context.TODO(), 1, 10, "")
  32. })
  33. }
  34. func Test_ArcDuration(t *testing.T) {
  35. Convey("ArcDuration", t, func() {
  36. eg, _ := errgroup.WithContext(context.TODO())
  37. var aids = []int64{10099744, 10099730, 10099729, 10099728, 10099726, 10099670, 10099669, 10099668, 10099667, 10099660, 10099653, 10099652, 10099651}
  38. for _, aid := range aids {
  39. id := aid
  40. eg.Go(func() (err error) {
  41. Println(s.ArcDuration(context.TODO(), id))
  42. return
  43. })
  44. }
  45. eg.Wait()
  46. Println(s.arcDurWithMutex.Durations)
  47. for aid, val := range s.arcDurWithMutex.Durations {
  48. Printf("aid(%d) dur(%d) gotTime(%d)\n", aid, val.Duration, val.GotTime)
  49. }
  50. })
  51. }
  52. func Test_SendStat(t *testing.T) {
  53. Convey("SendStat", t, func() {
  54. vmsg := &model.StatViewMsg{Type: "archive", ID: 123456, Count: 123456, Ts: time.Now().Unix()}
  55. err := s.statViewPub.Send(context.TODO(), "test", vmsg)
  56. So(err, ShouldBeNil)
  57. })
  58. }