Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCL测试完善计划 #2531

Open
5 of 10 tasks
Mixficsol opened this issue Mar 19, 2024 · 1 comment
Open
5 of 10 tasks

TCL测试完善计划 #2531

Mixficsol opened this issue Mar 19, 2024 · 1 comment
Labels

Comments

@Mixficsol
Copy link
Collaborator

Mixficsol commented Mar 19, 2024

TCL 测试覆盖现状

背景

目前 PikaTCL 集成测试移植了 Redis 的测试集,目前已经展开了测试类型包括 printver, basic, scan, expire, multi, quit, pubsub, slowlog, maxmemory, bitops, hyperloglog, type, acl, set, list, zset, string, hash这几个类型,由于 PikaRedis 之间存在一些差异,所以我们需要修改 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 样例被注释了是为什么?

  1. Pika 的有些命令与 Redis 命令并不是 100% 兼容的,具体可以查看 Pika 支持的 Redis 接口及兼容情况
  2. Pika 中的 Key 可以对应不同的数据结构,但是 Redis 中一个 Key 只能对应一种数据结构
  3. Pika 不支持 Redis 中的一些命令,比如: sort , rename 等等
  4. Pika 的返回值与 Redis 不一致,是一个 bug 需要进行修改

2. 我应该怎么去修改目前存在 bugPikaTCL 测试呢?

目前 PikaTCL 的代码在 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 测试样例有几种类型?

  1. 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}
  1. 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}
#    }
  1. 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
        #}
  1. 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
#    }
  1. 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}
#        }
  1. 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, ListGEO , Hyperloglog, Stream, Bitops 这几种常用的数据结构以及 Multi(事务)TCL 测试进行了注解补充,后续我们会继续对剩下类型的 TCL 测试进行注解补充

5.怎么对一个 TCL 测试进行修复?

只需要简单的 4 步,Pika 的 TCL 代码在 test/unit/ 目录下,我们以下面这个例子来说明:

  1. 我们可以用编辑器全局搜索上面提到的注解字样,比如 The return value of Pika is inconsistent with Redis
  2. 然后会跳转到相应的测试样例下方,例如下面这个代码就在 test/unit/type/zset.tcl 路径下
  3. 我们首先把这个 test 的注释先解掉,然后在 Pika 的根目录下执行 ./pikatest.sh type/zset clean 命令启动测试
  4. 根据测试提供的错误信息进行问题的修复,在问题修复后就可以把之前加上的注释解开了

测试样例代码 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 命令返回:

截屏2024-03-11 11 06 55

Redis 命令返回:

截屏2024-03-11 11 07 02

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 测试还需要进行修复

  • String (目前测试可以完整通过,完全和Redis一致)
  • Zset (目前测试可以完整通过,完全和Redis一致)
  • Set (目前测试可以完整通过,完全和Redis一致)
  • List (目前测试可以完整通过,完全和Redis一致)
  • Hash (目前测试可以完整通过,完全和Redis一致)
  • Bitops
  • Stream
  • Hyperloglog
  • Multi
  • GEO
@Mixficsol Mixficsol added the ☢️ Bug Something isn't working label Mar 19, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: TCL test improvement plan

@Mixficsol Mixficsol added test and removed ☢️ Bug Something isn't working labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants