mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-27 00:02:19 +08:00
Fix RDB.AggregationCheck when run against an empty group
This commit is contained in:
parent
b29fe58434
commit
4b35eb0e1a
@ -1009,6 +1009,9 @@ func (r *RDB) ListGroups(qname string) ([]string, error) {
|
|||||||
// Returns 1 if an aggregation set was created
|
// Returns 1 if an aggregation set was created
|
||||||
var aggregationCheckCmd = redis.NewScript(`
|
var aggregationCheckCmd = redis.NewScript(`
|
||||||
local size = redis.call("ZCARD", KEYS[1])
|
local size = redis.call("ZCARD", KEYS[1])
|
||||||
|
if size == 0 then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
local maxSize = tonumber(ARGV[1])
|
local maxSize = tonumber(ARGV[1])
|
||||||
if size >= maxSize then
|
if size >= maxSize then
|
||||||
local msgs = redis.call("ZRANGE", KEYS[1], 0, maxSize-1)
|
local msgs = redis.call("ZRANGE", KEYS[1], 0, maxSize-1)
|
||||||
|
@ -3129,6 +3129,26 @@ func TestAggregationCheck(t *testing.T) {
|
|||||||
wantAggregationSet []*base.TaskMessage
|
wantAggregationSet []*base.TaskMessage
|
||||||
wantGroups map[string]map[string][]base.Z
|
wantGroups map[string]map[string][]base.Z
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
desc: "with an empty group",
|
||||||
|
groups: map[string]map[string][]base.Z{
|
||||||
|
"default": {
|
||||||
|
"mygroup": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
qname: "default",
|
||||||
|
gname: "mygroup",
|
||||||
|
gracePeriod: 1 * time.Minute,
|
||||||
|
maxDelay: 10 * time.Minute,
|
||||||
|
maxSize: 5,
|
||||||
|
shouldCreateSet: false,
|
||||||
|
wantAggregationSet: nil,
|
||||||
|
wantGroups: map[string]map[string][]base.Z{
|
||||||
|
"default": {
|
||||||
|
"mygroup": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "with a group size reaching the max size",
|
desc: "with a group size reaching the max size",
|
||||||
groups: map[string]map[string][]base.Z{
|
groups: map[string]map[string][]base.Z{
|
||||||
|
Loading…
Reference in New Issue
Block a user