mc_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/job/main/reply-feed/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoPingMc(t *testing.T) {
  9. convey.Convey("PingMc", t, func(ctx convey.C) {
  10. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  11. err := d.PingMc(context.Background())
  12. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  13. ctx.So(err, convey.ShouldBeNil)
  14. })
  15. })
  16. })
  17. }
  18. func TestDaokeyReplyStat(t *testing.T) {
  19. convey.Convey("keyReplyStat", t, func(ctx convey.C) {
  20. var (
  21. rpID = int64(0)
  22. )
  23. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  24. p1 := keyReplyStat(rpID)
  25. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  26. ctx.So(p1, convey.ShouldNotBeNil)
  27. })
  28. })
  29. })
  30. }
  31. func TestDaoSetReplyStatMc(t *testing.T) {
  32. convey.Convey("SetReplyStatMc", t, func(ctx convey.C) {
  33. var (
  34. rs = &model.ReplyStat{RpID: 0}
  35. )
  36. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  37. err := d.SetReplyStatMc(context.Background(), rs)
  38. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestDaoReplyStatsMc(t *testing.T) {
  45. convey.Convey("ReplyStatsMc", t, func(ctx convey.C) {
  46. var (
  47. rpIDs = []int64{}
  48. hitRpIDs = []int64{}
  49. missedRpIDs = []int64{}
  50. c = context.Background()
  51. )
  52. for i := 0; i < 5000; i++ {
  53. d.RemReplyStatMc(c, int64(i))
  54. }
  55. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  56. for i := 0; i < 5000; i++ {
  57. if i%2 == 0 {
  58. err := d.SetReplyStatMc(c, &model.ReplyStat{RpID: int64(i)})
  59. if err != nil {
  60. t.Fatal(err)
  61. }
  62. hitRpIDs = append(hitRpIDs, int64(i))
  63. } else {
  64. missedRpIDs = append(missedRpIDs, int64(i))
  65. }
  66. rpIDs = append(rpIDs, int64(i))
  67. }
  68. rsMap, missIDs, err := d.ReplyStatsMc(c, rpIDs)
  69. ctx.Convey("Then err should be nil.rsMap,missIDs should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(len(rsMap), convey.ShouldEqual, len(hitRpIDs))
  72. ctx.So(len(missIDs), convey.ShouldEqual, len(missedRpIDs))
  73. })
  74. for _, rpID := range hitRpIDs {
  75. if err = d.RemReplyStatMc(c, rpID); err != nil {
  76. t.Fatal(err)
  77. }
  78. }
  79. })
  80. })
  81. }