summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
authorchenyang8094 <chenyang8094@users.noreply.github.com>2021-12-28 03:37:21 +0800
committerGitHub <noreply@github.com>2021-12-27 21:37:21 +0200
commitaf0b50f83a997ca3eb2e21fd9ee823ef15e12183 (patch)
tree2fbe1ee7abb832f936dc69780012fe8899f33f91 /tests/support
parentf810510bb2f96c19b82b59222ae63941eedc9c20 (diff)
downloadredis-af0b50f83a997ca3eb2e21fd9ee823ef15e12183.tar.gz
Tests: don't rely on the response of MEMORY USAGE when mem_allocator is not jemalloc (#10010)
It turns out that libc malloc can return an allocation of a different size on requests of the same size. this means that matching MEMORY USAGE of one key to another copy of the same data can fail. Solution: Keep running the test that calls MEMORY USAGE, but ignore the response. We do that by introducing a new utility function to get the memory usage, which always returns 1 when the allocator is not jemalloc. Other changes: Some formatting for datatype2.tcl Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/util.tcl10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index d11841894..c4f90b29e 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -1002,3 +1002,13 @@ proc prepare_value {size} {
}
return $_v
}
+
+proc memory_usage {key} {
+ set usage [r memory usage $key]
+ if {![string match {*jemalloc*} [s mem_allocator]]} {
+ # libc allocator can sometimes return a different size allocation for the same requested size
+ # this makes tests that rely on MEMORY USAGE unreliable, so instead we return a constant 1
+ set usage 1
+ }
+ return $usage
+}