retry_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "testing"
  7. artmdl "go-common/app/interface/openplatform/article/model"
  8. "go-common/app/job/openplatform/article/dao"
  9. "go-common/library/cache/redis"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. func Test_Retry(t *testing.T) {
  13. Convey("retry", t, WithoutProcService(func(s *Service) {
  14. var (
  15. err error
  16. c = context.TODO()
  17. )
  18. SkipConvey("push retry", func() {
  19. var (
  20. favCnt = int64(1)
  21. replyCnt = int64(2)
  22. statRetry = &dao.StatRetry{
  23. Data: &artmdl.StatMsg{
  24. Aid: 888,
  25. Favorite: &favCnt,
  26. Reply: &replyCnt,
  27. },
  28. Action: dao.RetryUpdateStatCache,
  29. Count: 3,
  30. }
  31. )
  32. err = s.dao.PushStat(c, statRetry)
  33. So(err, ShouldBeNil)
  34. })
  35. SkipConvey("pop retry", func() {
  36. bs, err := s.dao.PopStat(c)
  37. if err != redis.ErrNil {
  38. So(err, ShouldBeNil)
  39. }
  40. So(bs, ShouldNotBeEmpty)
  41. msg := &dao.StatRetry{}
  42. err = json.Unmarshal(bs, msg)
  43. So(err, ShouldBeNil)
  44. So(msg.Action, ShouldEqual, dao.RetryUpdateStatCache)
  45. So(msg.Count, ShouldEqual, 3)
  46. })
  47. Convey("retry reply", func() {
  48. err := s.dao.PushReply(context.TODO(), 8, 9)
  49. So(err, ShouldBeNil)
  50. aid, mid, err := s.dao.PopReply(c)
  51. So(err, ShouldBeNil)
  52. fmt.Println(aid)
  53. fmt.Println(mid)
  54. })
  55. }))
  56. }