Files
kv/tests/unit/moduleapi/test_lazyfree.tcl
zeekay ceddaa4db5 merge: upstream/unstable (-X ours, brand preserved)
# Conflicts:
#	AGENTS.md
#	AGENTS.md~upstream_unstable
#	deps/libkv/tests/ut_connect_fallback.c
#	deps/libvalkey/docs/standalone.md
#	src/dict.c
#	src/unit/test_fifo.c
#	src/unit/test_files.h
#	src/unit/test_help.h
#	src/unit/test_kv_strtod.c
#	src/unit/test_main.c
#	src/unit/test_mutexqueue.c
#	src/unit/test_util.c
#	tests/cluster/cluster.tcl
#	tests/cluster/run.tcl
#	tests/cluster/tests/03-failover-loop.tcl
#	tests/cluster/tests/04-resharding.tcl
#	tests/cluster/tests/07-replica-migration.tcl
#	tests/cluster/tests/12-replica-migration-2.tcl
#	tests/cluster/tests/12.1-replica-migration-3.tcl
#	tests/cluster/tests/28-cluster-shards.tcl
#	tests/cluster/tests/includes/init-tests.tcl
#	tests/cluster/tests/includes/utils.tcl
2026-06-02 10:21:23 -07:00

33 lines
1017 B
Tcl

set testmodule [file normalize tests/modules/test_lazyfree.so]
start_server {tags {"modules"}} {
r module load $testmodule
test "modules allocated memory can be reclaimed in the background" {
set orig_mem [s used_memory]
set rd [kv_deferring_client]
# LAZYFREE_THRESHOLD is 64
$rd client reply off
for {set i 0} {$i < 10000} {incr i} {
$rd lazyfreelink.insert lazykey $i
if {$i % 1000 == 0} {$rd flush}
}
$rd client reply on
assert_equal OK [$rd read]
assert {[r lazyfreelink.len lazykey] == 10000}
set peak_mem [s used_memory]
assert {[r unlink lazykey] == 1}
assert {$peak_mem > $orig_mem+10000}
wait_for_condition 50 100 {
[s used_memory] < $peak_mem &&
[s used_memory] < $orig_mem*2 &&
[string match {*lazyfreed_objects:1*} [r info Memory]]
} else {
fail "Module memory is not reclaimed by UNLINK"
}
}
}