summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorsundb <sundbcn@gmail.com>2023-03-07 15:06:58 +0800
committerGitHub <noreply@github.com>2023-03-07 09:06:58 +0200
commit3fba3ccd96b066d10401f1f9b65293d59d14082c (patch)
tree52f556783edf96661d67bc7656c5c6a8c8127b4d /tests/modules
parent3a90ea998c5bf56270227dff4f54a014b6522de7 (diff)
downloadredis-3fba3ccd96b066d10401f1f9b65293d59d14082c.tar.gz
Skip test for sdsRemoveFreeSpace when mem_allocator is not jemalloc (#11878)
Test `trim on SET with big value` (introduced from #11817) fails under mac m1 with libc mem_allocator. The reason is that malloc(33000) will allocate 65536 bytes(>42000). This test still passes under ubuntu with libc mem_allocator. ``` *** [err]: trim on SET with big value in tests/unit/type/string.tcl Expected [r memory usage key] < 42000 (context: type source line 471 file /Users/iospack/data/redis_fork/tests/unit/type/string.tcl cmd {assert {[r memory usage key] < 42000}} proc ::test) ``` simple test under mac m1 with libc mem_allocator: ```c void *p = zmalloc(33000); printf("malloc size: %zu\n", zmalloc_size(p)); # output malloc size: 65536 ```
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/basics.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/modules/basics.c b/tests/modules/basics.c
index 579d8f629..897cb5d87 100644
--- a/tests/modules/basics.c
+++ b/tests/modules/basics.c
@@ -417,11 +417,22 @@ int TestTrimString(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
size_t string_len = RedisModule_MallocSizeString(s);
RedisModule_TrimStringAllocation(s);
size_t len_after_trim = RedisModule_MallocSizeString(s);
- if (len_after_trim < string_len) {
+
+ /* Determine if using jemalloc memory allocator. */
+ RedisModuleServerInfoData *info = RedisModule_GetServerInfo(ctx, "memory");
+ const char *field = RedisModule_ServerInfoGetFieldC(info, "mem_allocator");
+ int use_jemalloc = !strncmp(field, "jemalloc", 8);
+
+ /* Jemalloc will reallocate `s` from 2k to 1k after RedisModule_TrimStringAllocation(),
+ * but non-jemalloc memory allocators may keep the old size. */
+ if ((use_jemalloc && len_after_trim < string_len) ||
+ (!use_jemalloc && len_after_trim <= string_len))
+ {
RedisModule_ReplyWithSimpleString(ctx, "OK");
} else {
RedisModule_ReplyWithError(ctx, "String was not trimmed as expected.");
}
+ RedisModule_FreeServerInfo(ctx, info);
RedisModule_Free(tmp);
RedisModule_FreeString(ctx,s);
return REDISMODULE_OK;