TCL测试完善计划
TCL 测试覆盖现状
背景
目前 Pika 的 TCL 集成测试移植了 Redis 的测试集,目前已经展开了测试类型包括 printver, basic, scan, expire, multi, quit, pubsub, slowlog, maxmemory, bitops, hyperloglog, type, acl, set, list, zset, string, hash这几个类型,由于 Pika 和 Redis 之间存在一些差异,所以我们需要修改 TCL 的代码来保证测试的正确性
快速入门 TCL
以这段代码举例, r 代表 Redis 执行,所以下面这段代码意思是先执行 Del novar 命令,然后再执行 setnx novar foobared 命令检查返回值是不是 1, 然后执行 get novar 检查返回值是不是 foobared,这就是一个最简单的 TCL 样例
test "SETNX target key missing" {
r del novar
assert_equal 1 [r setnx novar foobared]
assert_equal "foobared" [r get novar]
}
Q&A
1. 目前还有很多 TCL 样例被注释了是为什么?
Pika的有些命令与Redis命令并不是100%兼容的,具体可以查看 Pika 支持的 Redis 接口及兼容情况Pika中的Key可以对应不同的数据结构,但是Redis中一个Key只能对应一种数据结构Pika不支持Redis中的一些命令,比如:sort,rename等等Pika的返回值与Redis不一致,是一个bug需要进行修改
2. 我应该怎么去修改目前存在 bug 的 Pika 的 TCL 测试呢?
目前 Pika 的 TCL 的代码在 tests/unit 下方,以下面这个代码为例,对于所有存在 Bug 的测试样例,我们目前都已经打上了 Bug 注释,通过编辑器全局搜索 # The return value of Pika is inconsistent with Redis 关键字可以很容易找到,然后进行问题复现并进行修复,如果需要提 PR 修复的请关联此 issue, 当然如果你手动测试 Pika 发现了问题,同样也可以新加一个 TCL 的测试样例在相应文件下方,欢迎联系 @Mixficsol
# The return value of Pika is inconsistent with Redis
test {Extended SET GET option with no previous value} {
r del foo
set old_value [r set foo bar GET]
set new_value [r get foo]
list $old_value $new_value
} {{} bar}
3. 目前被注释掉的 TCL 测试样例有几种类型?
The return value of Pika is inconsistent with Redis(Redis 的返回值和 Pika 这边不一致)
# The return value of Pika is inconsistent with Redis
# test {ZINTERSTORE #516 regression, mixed sets and ziplist zsets} {
# r sadd one 100 101 102 103
# r sadd two 100 200 201 202
# r zadd three 1 500 1 501 1 502 1 503 1 100
# r zinterstore to_here 3 one two three WEIGHTS 0 0 1
# r zrange to_here 0 -1
# } {100}
Keys for multiple data types of Pika can be duplicate由于Pika中的Key可以对应不同的数据结构,但是Redis中一个Key只能对应一种数据结构这种情况导致的返回值不一致
# Keys for multiple data types of Pika can be duplicate
# test {SADD against non set} {
# r lpush mylist foo
# assert_error WRONGTYPE* {r sadd mylist bar}
# }
This parameter is not available in Pika(Redis 中有这个配置参数,但是 Pika 目前没有)
# This parameter is not available in Pika
#if {$encoding == "ziplist"} {
# r config set zset-max-ziplist-entries 128
# r config set zset-max-ziplist-value 64
#} elseif {$encoding == "skiplist"} {
# r config set zset-max-ziplist-entries 0
# r config set zset-max-ziplist-value 0
#} else {
# puts "Unknown sorted set encoding"
# exit
#}
Pika does not support the debug command(Pika 中暂未实现这个命令)
# Pika does not support the debug command
# test "Set encoding after DEBUG RELOAD" {
# r del myintset myhashset mylargeintset
# for {set i 0} {$i < 100} {incr i} { r sadd myintset $i }
# for {set i 0} {$i < 1280} {incr i} { r sadd mylargeintset $i }
# for {set i 0} {$i < 256} {incr i} { r sadd myhashset [format "i%03d" $i] }
# assert_encoding intset myintset
# assert_encoding hashtable mylargeintset
# assert_encoding hashtable myhashset
#
# r debug reload
# assert_encoding intset myintset
# assert_encoding hashtable mylargeintset
# assert_encoding hashtable myhashset
# }
No cause has been confirmed(暂时未确认原因)
# No cause has been confirmed
# test "$pop: with negative timeout" {
# set rd [redis_deferring_client]
# $rd $pop blist1 -1
# assert_error "ERR*is negative*" {$rd read}
# }
Currently Redis and Pika are consistent(Redis 官网的返回和 Pika 一致,考虑需要修改 TCL)
# Currently Redis and Pika are consistent
# test {LINDEX against non-list value error} {
# assert_error WRONGTYPE* {r lindex mylist 0}
# }
4. 现在所有的被注释掉的 TCL 测试都有以上这个相应的注解注释吗?
目前我们只对 Zset, Set, Hash, String, List,GEO , Hyperloglog, Stream, Bitops 这几种常用的数据结构以及 Multi(事务) 的 TCL 测试进行了注解补充,后续我们会继续对剩下类型的 TCL 测试进行注解补充
5.怎么对一个 TCL 测试进行修复?
只需要简单的 4 步,Pika 的 TCL 代码在 test/unit/ 目录下,我们以下面这个例子来说明:
- 我们可以用编辑器全局搜索上面提到的注解字样,比如
The return value of Pika is inconsistent with Redis - 然后会跳转到相应的测试样例下方,例如下面这个代码就在
test/unit/type/zset.tcl路径下 - 我们首先把这个 test 的注释先解掉,然后在 Pika 的根目录下执行
./pikatest.sh type/zset clean命令启动测试 - 根据测试提供的错误信息进行问题的修复,在问题修复后就可以把之前加上的注释解开了
测试样例代码 1:
test/unit/type/zset.tcl
# The return value of Pika is inconsistent with Redis
# test {ZINTERSTORE #516 regression, mixed sets and ziplist zsets} {
# r sadd one 100 101 102 103
# r sadd two 100 200 201 202
# r zadd three 1 500 1 501 1 502 1 503 1 100
# r zinterstore to_here 3 one two three WEIGHTS 0 0 1
# r zrange to_here 0 -1
# } {100}
Pika 命令返回:
Redis 命令返回:
TCL 测试目前进度
我们主要是对 1. The return value of Pika is inconsistent with Redis , 2. No cause has been confirmed, 3. Currently Redis and Pika are consistent 这三个注释类型优先进行修复,优先级从高到低,优先级最高的是 The return value of Pika is inconsistent with Redis。目前对 Stream,Bitops ,Hyperloglog ,Multi,GEO 测试还需要进行修复
- [x] String (目前测试可以完整通过,完全和Redis一致)
- [x] Zset (目前测试可以完整通过,完全和Redis一致)
- [x] Set (目前测试可以完整通过,完全和Redis一致)
- [x] List (目前测试可以完整通过,完全和Redis一致)
- [x] Hash (目前测试可以完整通过,完全和Redis一致)
- [ ] Bitops
- [ ] Stream
- [ ] Hyperloglog
- [ ] Multi
- [ ] GEO
Bot detected the issue body's language is not English, translate it automatically.
Title: TCL test improvement plan