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

Pika 的 TCL 测试完善计划 #2046

Closed
8 tasks
Mixficsol opened this issue Sep 27, 2023 · 0 comments · Fixed by #2464, #2468 or #2497
Closed
8 tasks

Pika 的 TCL 测试完善计划 #2046

Mixficsol opened this issue Sep 27, 2023 · 0 comments · Fixed by #2464, #2468 or #2497

Comments

@Mixficsol
Copy link
Collaborator

Mixficsol commented Sep 27, 2023

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 注释,通过编辑器全局搜索 # Bug need Fix 关键字可以很容易找到,然后进行问题复现并进行修复,如果需要提 PR 修复的请关联此 issue, 当然如果你手动测试 Pika 发现了问题,同样也可以新加一个 TCL 的测试样例在相应文件下方,欢迎联系 @Mixficsol

# Bug need Fix
    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. Bug need Fix (这是一个已经确认的 bug, 需要修复)
# Bug need Fix
   # 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, List 这五种常用的数据结构的 TCL 测试进行了注解补充,后续我们会继续对剩下类型的 TCL 测试进行注解补充

TCL 测试已知的问题

Zset:

  • ZINTERSTORE #516 regression, mixed sets and ziplist zsets

测试样例代码 1:
test/unit/type/zset.tcl

    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

Set:

  • SINTER against non-set should throw error
  • SUNION against non-set should throw error
  • SMOVE wrong src key type

测试样例代码 1:
test/unit/type/set.tcl

    test "SINTER against non-set should throw error" {
        r set key1 x
        assert_error "WRONGTYPE*" {r sinter key1 noset}
    }

Pika 命令返回:

截屏2024-03-11 11 27 24

Redis 命令返回:

截屏2024-03-11 11 28 06

测试样例代码 2:
test/unit/type/set.tcl

    test "SUNION against non-set should throw error" {
        r set key1 x
        assert_error "WRONGTYPE*" {r sunion key1 noset}
    }

Pika 命令返回:

截屏2024-03-11 11 30 56

Redis 命令返回:

截屏2024-03-11 11 31 29

测试样例代码 3:
test/unit/type/set.tcl

    test "SMOVE wrong src key type" {
        r set x 10
        assert_error "WRONGTYPE*" {r smove x myset2 foo}
    }

Pika 命令返回:

截屏2024-03-11 11 35 54

Redis 命令返回:

截屏2024-03-11 11 36 24

String:

  • SETRANGE against non-existing key
  • Extended SET GET option with XX
  • Extended SET GET option with no previous value

测试样例代码 1:
test/unit/type/string.tcl

    test "SETRANGE against non-existing key" {
        r del mykey
        assert_equal 3 [r setrange mykey 0 foo]
        assert_equal "foo" [r get mykey]

        r del mykey
        assert_equal 0 [r setrange mykey 0 ""]
        assert_equal 0 [r exists mykey]

        r del mykey
        assert_equal 4 [r setrange mykey 1 foo]
        assert_equal "\000foo" [r get mykey]
    }

Pika 命令返回:

截屏2024-03-11 15 42 05

Redis 命令返回:

截屏2024-03-11 15 42 15

测试样例代码 2:
test/unit/type/string.tcl

    test {Extended SET GET option with XX} {
        r del foo
        r set foo bar
        set old_value [r set foo baz GET XX]
        set new_value [r get foo]
        list $old_value $new_value
    } {bar baz}

Pika 命令返回:

截屏2024-03-11 15 54 33

Redis 命令返回:

截屏2024-03-11 15 54 52

测试样例代码 3:
test/unit/type/string.tcl

    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}

Pika 命令返回:

截屏2024-03-11 15 56 49

Redis 命令返回:

截屏2024-03-11 15 57 00

如何添加一段 TCL 的异常代码样例

如果你发现了一个 测试样例存在 Bug 是需要修复的,请使用一下的这个模版添加在这个文件里面

样例添加:

  • SUNION against non-set should throw error

测试样例代码:
test/unit/type/string.tcl (所在的文件路径)

对应的 tcl 代码

Pika 命令返回:

Pika 的返回截图

Redis 命令返回:

Redis 的返回截图

@Mixficsol Mixficsol assigned Mixficsol and unassigned Mixficsol Sep 27, 2023
@AlexStocks AlexStocks reopened this Feb 23, 2024
@Mixficsol Mixficsol reopened this Mar 2, 2024
@Mixficsol Mixficsol reopened this Mar 11, 2024
@Mixficsol Mixficsol changed the title Pika 完善集成测试和单元测试 Pika 的 TCL 测试完善计划 Mar 11, 2024
@Mixficsol Mixficsol reopened this Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants