Skip to content

Commit

Permalink
test against 7.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Sep 27, 2023
1 parent 64c0ce8 commit dc54bd8
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Commands which will probably not be implemented:

## &c.

Integration tests are run against Redis 7.0.7. The [./integration](./integration/) subdir
Integration tests are run against Redis 7.2.0. The [./integration](./integration/) subdir
compares miniredis against a real redis instance.

The Redis 6 RESP3 protocol is supported. If there are problems, please open
Expand Down
6 changes: 3 additions & 3 deletions cmd_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ func TestBrpop(t *testing.T) {
)
mustDo(t, c,
"BRPOP", "key", "inf",
proto.Error("ERR timeout is negative"),
proto.Error("ERR timeout is out of range"),
)
})
}
Expand Down Expand Up @@ -1415,7 +1415,7 @@ func TestBlpop(t *testing.T) {
)
mustDo(t, c,
"BLPOP", "key", "inf",
proto.Error("ERR timeout is negative"),
proto.Error("ERR timeout is out of range"),
)
})
}
Expand Down Expand Up @@ -1478,7 +1478,7 @@ func TestBrpoplpush(t *testing.T) {
)
mustDo(t, c,
"BRPOPLPUSH", "key", "foo", "inf",
proto.Error("ERR timeout is negative"),
proto.Error("ERR timeout is out of range"),
)
mustDo(t, c,
"BRPOPLPUSH", "key", "foo", "1", "baz",
Expand Down
8 changes: 7 additions & 1 deletion cmd_sorted_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func (m *Miniredis) makeCmdZrangebyscore(reverse bool) server.Cmd {
// ZRANK and ZREVRANK
func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
return func(c *server.Peer, cmd string, args []string) {
if len(args) != 2 {
if len(args) < 2 {
setDirty(c)
c.WriteError(errWrongNumber(cmd))
return
Expand All @@ -778,6 +778,12 @@ func (m *Miniredis) makeCmdZrank(reverse bool) server.Cmd {
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)

if len(args) > 2 {
setDirty(c)
c.WriteError(msgSyntaxError)
return
}

if !db.exists(key) {
c.WriteNull()
return
Expand Down
2 changes: 1 addition & 1 deletion cmd_sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestSortedSet(t *testing.T) {
)
mustDo(t, c,
"ZRANK", "set", "spurious", "args",
proto.Error(errWrongNumber("zrank")),
proto.Error(msgSyntaxError),
)

mustDo(t, c,
Expand Down
27 changes: 21 additions & 6 deletions cmd_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ func (m *Miniredis) cmdXinfoConsumers(c *server.Peer, args []string) {
c.WriteError(errWrongNumber("CONSUMERS"))
return
}
key := args[0]
groupName := args[1]
key, groupName := args[0], args[1]

withTx(m, c, func(c *server.Peer, ctx *connCtx) {
db := m.db(ctx.selectedDB)
Expand All @@ -643,25 +642,37 @@ func (m *Miniredis) cmdXinfoConsumers(c *server.Peer, args []string) {
return
}

consumerNames := make([]string, 0)
var consumerNames []string
for name := range g.consumers {
consumerNames = append(consumerNames, name)
}
sort.Strings(consumerNames)

c.WriteLen(len(consumerNames))
for _, name := range consumerNames {
c.WriteMapLen(2)
cons := g.consumers[name]

c.WriteMapLen(4)
c.WriteBulk("name")
c.WriteBulk(name)

c.WriteBulk("pending")
c.WriteInt(g.consumers[name].numPendingEntries)
c.WriteInt(cons.numPendingEntries)
// TODO: these times aren't set for all commands
c.WriteBulk("idle")
c.WriteInt(m.sinceMilli(cons.lastSeen))
c.WriteBulk("inactive")
c.WriteInt(m.sinceMilli(cons.lastSuccess))
}
})
}

func (m *Miniredis) sinceMilli(t time.Time) int {
if t.IsZero() {
return -1
}
return int(m.effectiveNow().Sub(t).Milliseconds())
}

// XREADGROUP
func (m *Miniredis) cmdXreadgroup(c *server.Peer, cmd string, args []string) {
// XREADGROUP GROUP group consumer STREAMS key ID
Expand Down Expand Up @@ -1708,6 +1719,7 @@ func (m *Miniredis) xclaim(
for _, id := range ids {
pelPos, pelEntry := group.searchPending(id)
if pelEntry == nil {
group.setLastSeen(consumerName, m.effectiveNow())
if !force {
continue
}
Expand All @@ -1724,6 +1736,7 @@ func (m *Miniredis) xclaim(
consumer: consumerName,
deliveryCount: 1,
}
group.setLastSuccess(consumerName, m.effectiveNow())
} else {
group.consumers[pelEntry.consumer].numPendingEntries--
pelEntry.consumer = consumerName
Expand All @@ -1744,6 +1757,7 @@ func (m *Miniredis) xclaim(
claimedEntryIDs = append(claimedEntryIDs, id)
}
if len(claimedEntryIDs) == 0 {
group.setLastSeen(consumerName, m.effectiveNow())
return
}

Expand All @@ -1753,6 +1767,7 @@ func (m *Miniredis) xclaim(
consumer := group.consumers[consumerName]
consumer.numPendingEntries += len(claimedEntryIDs)

group.setLastSuccess(consumerName, m.effectiveNow())
return
}

Expand Down
46 changes: 43 additions & 3 deletions cmd_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ func TestStreamGroup(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(0),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand Down Expand Up @@ -797,6 +799,8 @@ func TestStreamReadGroup(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(1),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand Down Expand Up @@ -928,6 +932,8 @@ func TestStreamAck(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(0),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand Down Expand Up @@ -1211,6 +1217,8 @@ func TestStreamAutoClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(1),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand All @@ -1233,6 +1241,8 @@ func TestStreamAutoClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(2),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand Down Expand Up @@ -1296,6 +1306,8 @@ func TestStreamAutoClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(2),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand All @@ -1318,10 +1330,14 @@ func TestStreamAutoClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(0),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
proto.Array(
proto.String("name"), proto.String("bob"),
proto.String("pending"), proto.Int(2),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand All @@ -1343,10 +1359,14 @@ func TestStreamAutoClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(1),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
proto.Array(
proto.String("name"), proto.String("bob"),
proto.String("pending"), proto.Int(1),
proto.String("idle"), proto.Int(-1),
proto.String("inactive"), proto.Int(-1),
),
),
)
Expand Down Expand Up @@ -1420,7 +1440,14 @@ func TestStreamClaim(t *testing.T) {
)
mustDo(t, c,
"XINFO", "CONSUMERS", "planets", "processing",
proto.Array(),
proto.Array(
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(0),
proto.String("idle"), proto.Int(0),
proto.String("inactive"), proto.Int(-1),
),
),
)

mustDo(t, c,
Expand Down Expand Up @@ -1467,6 +1494,8 @@ func TestStreamClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(2),
proto.String("idle"), proto.Int(0),
proto.String("inactive"), proto.Int(0),
),
),
)
Expand Down Expand Up @@ -1502,7 +1531,7 @@ func TestStreamClaim(t *testing.T) {
proto.Array(
proto.Array(
proto.String("name"), proto.String("processing"),
proto.String("consumers"), proto.Int(1),
proto.String("consumers"), proto.Int(2),
proto.String("pending"), proto.Int(1),
proto.String("last-delivered-id"), proto.String("0-0"),
proto.String("entries-read"), proto.Nil,
Expand All @@ -1516,8 +1545,15 @@ func TestStreamClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(1),
proto.String("idle"), proto.Int(20000),
proto.String("inactive"), proto.Int(20000),
),
proto.Array(
proto.String("name"), proto.String("bob"),
proto.String("pending"), proto.Int(0),
proto.String("idle"), proto.Int(0),
proto.String("inactive"), proto.Int(-1),
),
// bob only has a deleted one
),
)
mustDo(t, c,
Expand Down Expand Up @@ -1630,10 +1666,14 @@ func TestStreamClaim(t *testing.T) {
proto.Array(
proto.String("name"), proto.String("alice"),
proto.String("pending"), proto.Int(3),
proto.String("idle"), proto.Int(20000),
proto.String("inactive"), proto.Int(20000),
),
proto.Array(
proto.String("name"), proto.String("bob"),
proto.String("pending"), proto.Int(0), // deleted
proto.String("idle"), proto.Int(0),
proto.String("inactive"), proto.Int(0),
),
),
)
Expand Down
2 changes: 1 addition & 1 deletion integration/get_redis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

VERSION=7.0.7
VERSION=7.2.0

rm -rf ./redis_src/
mkdir -p ./redis_src/
Expand Down
10 changes: 5 additions & 5 deletions integration/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func TestBrpop(t *testing.T) {
c.Do("LPUSH", "l", "one")
c.Do("BRPOP", "l", "1")
c.Do("BRPOP", "l", "0.1")
c.Error("negative", "BRPOP", "l", "inf")
c.Error("timeout is out of range", "BRPOP", "l", "inf")
c.Do("EXISTS", "l")

// transaction
Expand All @@ -432,7 +432,7 @@ func TestBrpop(t *testing.T) {
c.Error("not a float", "BRPOP", "l", "X")
c.Error("not a float", "BRPOP", "l", "")
c.Error("wrong number", "BRPOP", "1")
c.Error("negative", "BRPOP", "key", "-1")
c.Error("timeout is negative", "BRPOP", "key", "-1")
})
}

Expand Down Expand Up @@ -481,7 +481,7 @@ func TestBlpop(t *testing.T) {
c.Error("not a float", "BLPOP", "l", "X")
c.Error("not a float", "BLPOP", "l", "")
c.Error("wrong number", "BLPOP", "1")
c.Error("negative", "BLPOP", "key", "-1")
c.Error("timeout is negative", "BLPOP", "key", "-1")
})

testMulti(t,
Expand Down Expand Up @@ -515,8 +515,8 @@ func TestBrpoplpush(t *testing.T) {
c.Error("wrong number", "BRPOPLPUSH", "l")
c.Error("wrong number", "BRPOPLPUSH", "l", "x")
c.Error("wrong number", "BRPOPLPUSH", "1")
c.Error("negative", "BRPOPLPUSH", "from", "to", "-1")
c.Error("negative", "BRPOPLPUSH", "from", "to", "inf")
c.Error("timeout is negative", "BRPOPLPUSH", "from", "to", "-1")
c.Error("out of range", "BRPOPLPUSH", "from", "to", "inf")
c.Error("wrong number", "BRPOPLPUSH", "from", "to", "-1", "xxx")
})

Expand Down
2 changes: 1 addition & 1 deletion integration/sorted_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestSortedSet(t *testing.T) {
c.Error("wrong kind", "ZCARD", "str")
c.Error("wrong number", "ZRANK")
c.Error("wrong number", "ZRANK", "key")
c.Error("wrong number", "ZRANK", "key", "too", "many")
c.Error("syntax error", "ZRANK", "key", "too", "many")
c.Error("wrong kind", "ZRANK", "str", "member")
c.Error("wrong number", "ZREVRANK")
c.Error("wrong number", "ZREVRANK", "key")
Expand Down
6 changes: 3 additions & 3 deletions integration/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestStream(t *testing.T) {
c.Error("wrong number", "XREAD", "STREAMS", "foo")
c.Do("XREAD", "STREAMS", "foo", "0")
c.Error("wrong number", "XREAD", "STREAMS", "ordplanets")
c.Error("Unbalanced XREAD", "XREAD", "STREAMS", "ordplanets", "foo", "0")
c.Error("Unbalanced 'xread'", "XREAD", "STREAMS", "ordplanets", "foo", "0")
c.Error("wrong number", "XREAD", "COUNT")
c.Error("wrong number", "XREAD", "COUNT", "notint")
c.Error("wrong number", "XREAD", "COUNT", "10") // No streams
Expand Down Expand Up @@ -670,13 +670,13 @@ func TestStreamGroup(t *testing.T) {
c.Do("XGROUP", "CREATE", "planets", "processing", "$", "MKSTREAM")
c.Error("No such key", "XCLAIM", "planets", "foo", "alice", "0", "0-0")
c.Do("XCLAIM", "planets", "processing", "alice", "0", "0-0")
c.Do("XINFO", "CONSUMERS", "planets", "processing")
c.DoLoosely("XINFO", "CONSUMERS", "planets", "processing") // "idle" is fiddly

c.Do("XADD", "planets", "0-1", "name", "Mercury")
c.Do("XADD", "planets", "0-2", "name", "Venus")

c.Do("XCLAIM", "planets", "processing", "alice", "0", "0-1")
c.Do("XINFO", "CONSUMERS", "planets", "processing")
c.DoLoosely("XINFO", "CONSUMERS", "planets", "processing") // "idle" is fiddly

c.Do("XCLAIM", "planets", "processing", "alice", "0", "0-1", "0-2", "FORCE")
c.Do("XINFO", "GROUPS", "planets")
Expand Down
9 changes: 7 additions & 2 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ func optDuration(c *server.Peer, src string, dest *time.Duration) bool {
c.WriteError(msgInvalidTimeout)
return false
}
if n < 0 || math.IsInf(n, 0) {
if n < 0 {
setDirty(c)
c.WriteError(msgNegTimeout)
c.WriteError(msgTimeoutNegative)
return false
}
if math.IsInf(n, 0) {
setDirty(c)
c.WriteError(msgTimeoutIsOutOfRange)
return false
}

Expand Down

0 comments on commit dc54bd8

Please sign in to comment.