summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2022-11-22 22:38:27 +0800
committerGitHub <noreply@github.com>2022-11-22 16:38:27 +0200
commit543e0daa6302f87478c660d2b96b2151afbf2c6a (patch)
tree6bf3094177fdeb0320e29a042593d5fbf0fc04d1
parent6e9724cb6a8ff2bad4c8aeb591ee0d14120ca7af (diff)
downloadredis-543e0daa6302f87478c660d2b96b2151afbf2c6a.tar.gz
Make assert_refcount skip the OBJECT REFCOUNT check with needs:debug tag (#11487)
This PR add `assert_refcount_morethan`, and modify `assert_refcount` to skip the `OBJECT REFCOUNT` check with `needs:debug` flag. Use them to modify all `OBJECT REFCOUNT` calls and also update the tests/README to be more specific. The reasoning is that some of these tests could be testing something important, and along the way also add a check for the refcount, and it could be a shame to skip the whole test just because the refcount functionality is missing or blocked. but much like the fact that some redis variants may not support DEBUG, and still we want to run the majority of the test for coverage, and just skip the digest match.
-rw-r--r--tests/README.md4
-rw-r--r--tests/support/test.tcl13
-rw-r--r--tests/unit/maxmemory.tcl8
-rw-r--r--tests/unit/type/incr.tcl10
4 files changed, 24 insertions, 11 deletions
diff --git a/tests/README.md b/tests/README.md
index 4b2251bc5..1aa98dc9f 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -40,12 +40,12 @@ The following compatibility and capability tags are currently used:
| `large-memory` | Test that requires more than 100mb |
| `tls:skip` | Not compatible with `--tls`. |
| `needs:repl` | Uses replication and needs to be able to `SYNC` from server. |
-| `needs:debug` | Uses the `DEBUG` command or other debugging focused commands (like `OBJECT`). |
+| `needs:debug` | Uses the `DEBUG` command or other debugging focused commands (like `OBJECT REFCOUNT`). |
| `needs:pfdebug` | Uses the `PFDEBUG` command. |
| `needs:config-maxmemory` | Uses `CONFIG SET` to manipulate memory limit, eviction policies, etc. |
| `needs:config-resetstat` | Uses `CONFIG RESETSTAT` to reset statistics. |
| `needs:reset` | Uses `RESET` to reset client connections. |
-| `needs:save` | Uses `SAVE` to create an RDB file. |
+| `needs:save` | Uses `SAVE` or `BGSAVE` to create an RDB file. |
When using an external server (`--host` and `--port`), filtering using the
`external:skip` tags is done automatically.
diff --git a/tests/support/test.tcl b/tests/support/test.tcl
index 34b5aad29..2fe52f475 100644
--- a/tests/support/test.tcl
+++ b/tests/support/test.tcl
@@ -103,10 +103,23 @@ proc assert_type {type key} {
}
proc assert_refcount {ref key} {
+ if {[lsearch $::denytags "needs:debug"] >= 0} {
+ return
+ }
+
set val [r object refcount $key]
assert_equal $ref $val
}
+proc assert_refcount_morethan {key ref} {
+ if {[lsearch $::denytags "needs:debug"] >= 0} {
+ return
+ }
+
+ set val [r object refcount $key]
+ assert_morethan $val $ref
+}
+
# Wait for the specified condition to be true, with the specified number of
# max retries and delay between retries. Otherwise the 'elsescript' is
# executed.
diff --git a/tests/unit/maxmemory.tcl b/tests/unit/maxmemory.tcl
index 631b3ac91..564250f2e 100644
--- a/tests/unit/maxmemory.tcl
+++ b/tests/unit/maxmemory.tcl
@@ -147,14 +147,14 @@ start_server {tags {"maxmemory external:skip"}} {
test "Without maxmemory small integers are shared" {
r config set maxmemory 0
r set a 1
- assert {[r object refcount a] > 1}
+ assert_refcount_morethan a 1
}
test "With maxmemory and non-LRU policy integers are still shared" {
r config set maxmemory 1073741824
r config set maxmemory-policy allkeys-random
r set a 1
- assert {[r object refcount a] > 1}
+ assert_refcount_morethan a 1
}
test "With maxmemory and LRU policy integers are not shared" {
@@ -163,8 +163,8 @@ start_server {tags {"maxmemory external:skip"}} {
r set a 1
r config set maxmemory-policy volatile-lru
r set b 1
- assert {[r object refcount a] == 1}
- assert {[r object refcount b] == 1}
+ assert_refcount 1 a
+ assert_refcount 1 b
r config set maxmemory 0
}
diff --git a/tests/unit/type/incr.tcl b/tests/unit/type/incr.tcl
index b7446850e..7732921d9 100644
--- a/tests/unit/type/incr.tcl
+++ b/tests/unit/type/incr.tcl
@@ -63,18 +63,18 @@ start_server {tags {"incr"}} {
test {INCR uses shared objects in the 0-9999 range} {
r set foo -1
r incr foo
- assert {[r object refcount foo] > 1}
+ assert_refcount_morethan foo 1
r set foo 9998
r incr foo
- assert {[r object refcount foo] > 1}
+ assert_refcount_morethan foo 1
r incr foo
- assert {[r object refcount foo] == 1}
- } {} {needs:debug}
+ assert_refcount 1 foo
+ }
test {INCR can modify objects in-place} {
r set foo 20000
r incr foo
- assert {[r object refcount foo] == 1}
+ assert_refcount 1 foo
set old [lindex [split [r debug object foo]] 1]
r incr foo
set new [lindex [split [r debug object foo]] 1]