Skip to content

Commit

Permalink
Test: basic lazyfree unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Oct 9, 2015
1 parent 363c0f6 commit 6ddcba6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_helper.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ set ::all_tests {
unit/bitops
unit/memefficiency
unit/hyperloglog
unit/lazyfree
}
# Index to the next test to run in the ::all_tests list.
set ::next_test 0
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/lazyfree.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
start_server {tags {"lazyfree"}} {
test "UNLINK can reclaim memory in background" {
set orig_mem [s used_memory]
set args {}
for {set i 0} {$i < 100000} {incr i} {
lappend args $i
}
r sadd myset {*}$args
assert {[r scard myset] == 100000}
set peak_mem [s used_memory]
assert {[r unlink myset] == 1}
assert {$peak_mem > $orig_mem+1000000}
wait_for_condition 50 100 {
[s used_memory] < $peak_mem &&
[s used_memory] < $orig_mem*2
} else {
fail "Memory is not reclaimed by UNLINK"
}
}

test "FLUSHDB ASYNC can reclaim memory in background" {
set orig_mem [s used_memory]
set args {}
for {set i 0} {$i < 100000} {incr i} {
lappend args $i
}
r sadd myset {*}$args
assert {[r scard myset] == 100000}
set peak_mem [s used_memory]
r flushdb async
assert {$peak_mem > $orig_mem+1000000}
wait_for_condition 50 100 {
[s used_memory] < $peak_mem &&
[s used_memory] < $orig_mem*2
} else {
fail "Memory is not reclaimed by FLUSHDB ASYNC"
}
}
}

0 comments on commit 6ddcba6

Please sign in to comment.