task_test.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. package redis
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/admin/main/aegis/model/common"
  6. modtask "go-common/app/admin/main/aegis/model/task"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. task1 = &modtask.Task{
  11. ID: 1,
  12. BusinessID: 1,
  13. FlowID: 1,
  14. RID: 1,
  15. Gtime: 0,
  16. Weight: 10,
  17. }
  18. task2 = &modtask.Task{
  19. ID: 2,
  20. BusinessID: 1,
  21. FlowID: 1,
  22. RID: 2,
  23. Gtime: 0,
  24. Weight: 8,
  25. }
  26. task3 = &modtask.Task{
  27. ID: 3,
  28. BusinessID: 1,
  29. FlowID: 1,
  30. RID: 3,
  31. Gtime: 0,
  32. Weight: 8,
  33. }
  34. )
  35. func TestRedisSetTask(t *testing.T) {
  36. convey.Convey("SetTask", t, func(ctx convey.C) {
  37. var (
  38. c = context.Background()
  39. )
  40. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  41. err := d.SetTask(c, task1, task2, task3)
  42. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestRedisPushPublicTask(t *testing.T) {
  49. convey.Convey("PushPublicTask", t, func(ctx convey.C) {
  50. var (
  51. c = context.Background()
  52. )
  53. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  54. err := d.PushPublicTask(c, task1, task2, task3)
  55. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestRedisRemovePublicTask(t *testing.T) {
  62. convey.Convey("RemovePublicTask", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. opt = &common.BaseOptions{
  66. BusinessID: 1,
  67. FlowID: 1,
  68. }
  69. )
  70. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  71. err := d.RemovePublicTask(c, opt, 1, 2, 3)
  72. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. })
  75. })
  76. })
  77. }
  78. func TestRedisPushPersonalTask(t *testing.T) {
  79. convey.Convey("PushPersonalTask", t, func(ctx convey.C) {
  80. var (
  81. c = context.Background()
  82. opt = &common.BaseOptions{
  83. BusinessID: 1,
  84. FlowID: 1,
  85. UID: 1,
  86. }
  87. )
  88. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  89. err := d.PushPersonalTask(c, opt, 1, 2, 3)
  90. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  91. ctx.So(err, convey.ShouldBeNil)
  92. })
  93. })
  94. })
  95. }
  96. func TestRedisCountPersonalTask(t *testing.T) {
  97. convey.Convey("CountPersonalTask", t, func(ctx convey.C) {
  98. var (
  99. c = context.Background()
  100. opt = &common.BaseOptions{
  101. BusinessID: 1,
  102. FlowID: 1,
  103. UID: 1,
  104. }
  105. )
  106. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  107. _, err := d.CountPersonalTask(c, opt)
  108. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  109. ctx.So(err, convey.ShouldBeNil)
  110. })
  111. })
  112. })
  113. }
  114. func TestRedisRangePersonalTask(t *testing.T) {
  115. convey.Convey("RangePersonalTask", t, func(ctx convey.C) {
  116. var (
  117. c = context.Background()
  118. opt = &modtask.ListOptions{
  119. BaseOptions: common.BaseOptions{
  120. BusinessID: 1,
  121. FlowID: 1,
  122. UID: 1},
  123. Pager: common.Pager{
  124. Pn: 1,
  125. Ps: 20,
  126. },
  127. }
  128. )
  129. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  130. _, _, _, _, err := d.RangePersonalTask(c, opt)
  131. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  132. ctx.So(err, convey.ShouldBeNil)
  133. })
  134. })
  135. })
  136. }
  137. func TestRedisRemovePersonalTask(t *testing.T) {
  138. convey.Convey("RemovePersonalTask", t, func(ctx convey.C) {
  139. var (
  140. c = context.Background()
  141. opt = &common.BaseOptions{
  142. BusinessID: 1,
  143. FlowID: 1,
  144. UID: 1,
  145. }
  146. )
  147. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  148. err := d.RemovePersonalTask(c, opt, 1, 2, 3)
  149. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  150. ctx.So(err, convey.ShouldBeNil)
  151. })
  152. })
  153. })
  154. }
  155. func TestRedisPushDelayTask(t *testing.T) {
  156. convey.Convey("PushDelayTask", t, func(ctx convey.C) {
  157. var (
  158. c = context.Background()
  159. opt = &common.BaseOptions{
  160. BusinessID: 1,
  161. FlowID: 1,
  162. UID: 1,
  163. }
  164. )
  165. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  166. err := d.PushDelayTask(c, opt, 1, 2, 3)
  167. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  168. ctx.So(err, convey.ShouldBeNil)
  169. })
  170. })
  171. })
  172. }
  173. func TestRedisRangeDealyTask(t *testing.T) {
  174. convey.Convey("RangeDealyTask", t, func(ctx convey.C) {
  175. var (
  176. c = context.Background()
  177. opt = &modtask.ListOptions{
  178. BaseOptions: common.BaseOptions{
  179. BusinessID: 1,
  180. FlowID: 1,
  181. UID: 1},
  182. Pager: common.Pager{
  183. Pn: 1,
  184. Ps: 20,
  185. },
  186. }
  187. )
  188. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  189. tasks, count, hitids, _, err := d.RangeDealyTask(c, opt)
  190. ctx.Convey("Then err should be nil.tasks,count,hitids,missids should not be nil.", func(ctx convey.C) {
  191. ctx.So(err, convey.ShouldBeNil)
  192. ctx.So(hitids, convey.ShouldNotBeNil)
  193. ctx.So(count, convey.ShouldNotBeNil)
  194. ctx.So(tasks, convey.ShouldNotBeNil)
  195. })
  196. })
  197. })
  198. }
  199. func TestRedisRelease(t *testing.T) {
  200. convey.Convey("Release", t, func(ctx convey.C) {
  201. var (
  202. c = context.Background()
  203. opt = &common.BaseOptions{
  204. BusinessID: 1,
  205. FlowID: 1,
  206. UID: 1,
  207. }
  208. )
  209. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  210. err := d.Release(c, opt, true)
  211. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  212. ctx.So(err, convey.ShouldBeNil)
  213. })
  214. })
  215. })
  216. }
  217. func TestRedisrangefunc(t *testing.T) {
  218. convey.Convey("rangefunc", t, func(ctx convey.C) {
  219. var (
  220. c = context.Background()
  221. opt = &modtask.ListOptions{
  222. BaseOptions: common.BaseOptions{
  223. BusinessID: 1,
  224. FlowID: 1,
  225. UID: 1},
  226. Pager: common.Pager{
  227. Pn: 1,
  228. Ps: 20,
  229. },
  230. }
  231. )
  232. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  233. _, _, _, _, err := d.rangefuncCluster(c, "public", opt)
  234. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  235. ctx.So(err, convey.ShouldBeNil)
  236. })
  237. })
  238. })
  239. }
  240. func TestRedisSeize(t *testing.T) {
  241. convey.Convey("SeizeTask", t, func(ctx convey.C) {
  242. var (
  243. c = context.Background()
  244. )
  245. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  246. _, _, _, err := d.SeizeTask(c, 1, 1, 1, 10)
  247. ctx.Convey("Then err should be nil.tasks,count,hitids,missids should not be nil.", func(ctx convey.C) {
  248. ctx.So(err, convey.ShouldBeNil)
  249. })
  250. })
  251. })
  252. }
  253. func TestRedisRemoveDelayTask(t *testing.T) {
  254. convey.Convey("RemoveDelayTask", t, func(ctx convey.C) {
  255. var (
  256. c = context.Background()
  257. opt = &common.BaseOptions{}
  258. ids = interface{}(0)
  259. )
  260. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  261. err := d.RemoveDelayTask(c, opt, ids)
  262. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  263. ctx.So(err, convey.ShouldBeNil)
  264. })
  265. })
  266. })
  267. }
  268. func TestRedispushList(t *testing.T) {
  269. convey.Convey("pushList", t, func(ctx convey.C) {
  270. var (
  271. c = context.Background()
  272. key = ""
  273. values = int64(0)
  274. )
  275. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  276. err := d.pushList(c, key, values)
  277. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  278. ctx.So(err, convey.ShouldBeNil)
  279. })
  280. })
  281. })
  282. }
  283. func TestRedisremoveList(t *testing.T) {
  284. convey.Convey("removeList", t, func(ctx convey.C) {
  285. var (
  286. c = context.Background()
  287. key = ""
  288. ids = interface{}(0)
  289. )
  290. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  291. err := d.removeList(c, key, ids)
  292. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  293. ctx.So(err, convey.ShouldBeNil)
  294. })
  295. })
  296. })
  297. }
  298. func TestRedisGetTask(t *testing.T) {
  299. convey.Convey("GetTask", t, func(ctx convey.C) {
  300. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  301. _, err := d.GetTask(cntx, []int64{1, 2, 3})
  302. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  303. ctx.So(err, convey.ShouldBeNil)
  304. })
  305. })
  306. })
  307. }