From 27b8e8cdd89d882ea57dde812deb091bc840f82e Mon Sep 17 00:00:00 2001 From: benschermel Date: Wed, 18 Dec 2019 00:24:07 -0500 Subject: [PATCH 1/2] adding flash test Former-commit-id: 8c0f0bd1b5c83027e64765f9942f284bdb8ebcb4 --- tests/assets/default.conf | 1 + tests/test_helper.tcl | 1 + tests/unit/flash.tcl | 44 +++++++++++++++++++++++++++++++++++++++ tests/unit/flash.tcl.save | 40 +++++++++++++++++++++++++++++++++++ tests/unit/maxmemory.tcl | 1 - 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/unit/flash.tcl create mode 100644 tests/unit/flash.tcl.save diff --git a/tests/assets/default.conf b/tests/assets/default.conf index d7b8a75c6..fc61c6b52 100644 --- a/tests/assets/default.conf +++ b/tests/assets/default.conf @@ -25,3 +25,4 @@ appendonly no appendfsync everysec no-appendfsync-on-rewrite no activerehashing yes + diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index a06afca3e..9bf1bbf33 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -53,6 +53,7 @@ set ::all_tests { unit/slowlog unit/scripting unit/maxmemory + unit/flash unit/introspection unit/introspection-2 unit/limits diff --git a/tests/unit/flash.tcl b/tests/unit/flash.tcl new file mode 100644 index 000000000..aea00dab3 --- /dev/null +++ b/tests/unit/flash.tcl @@ -0,0 +1,44 @@ +start_server {tags {"flash"} overrides {"storage-provider flash /mnt/tmp"}} { + + foreach policy { + allkeys-random allkeys-lru allkeys-lfu + } { + test "FLASH - is eviction working without data loss (successfully stored to flash)? (policy $policy)" { + # make sure to start with a blank instance + r flushall + # Get the current memory limit and calculate a new limit. + # Set limit to 100M. + set used [s used_memory] + set limit [expr {$used+100000*1024}] + r config set maxmemory $limit + r config set maxmemory-policy $policy + # Now add keys equivalent to 1024b until the limit is almost reached. + set numkeys 0 + r set first val + while 1 { + r set $numkeys xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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it for maxmemory, however all keys set should still exist between flash and memory + # check same number of keys exist in addition to values of first and last keys + set err 0 + for {set j 0} {$j < 10000} {incr j} { + catch { + r set p2$j xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + } err + assert {$err == {OK}} + } + r set last val + set dbsize [r dbsize] + assert {[s used_memory] < $limit+4096} + assert {$dbsize == $numkeys+10002} + assert {[r get first] == {val}} + assert {[r get last] == {val}} + } + } +} + diff --git a/tests/unit/flash.tcl.save b/tests/unit/flash.tcl.save new file mode 100644 index 000000000..315baa4bb --- /dev/null +++ b/tests/unit/flash.tcl.save @@ -0,0 +1,40 @@ +start_server {tags {"flash"} overrides {"storage-provider flash /mnt/tmp/"}} { + test "Without maxmemory small integers are shared" { + r config set maxmemory 0 + r set a 1 + assert {[r object refcount a] > 1} + } + + foreach policy { + allkeys-random allkeys-lru allkeys-lfu + } { + test "maxmemory - is the memory limit honoured? (policy $policy)" { + # make sure to start with a blank instance + r flushall + # Get the current memory limit and calculate a new limit. + # We just add 100k to the current memory size so that it is + # fast for us to reach that limit. + set used [s used_memory] + set limit [expr {$used+100000*1024}] + r config set maxmemory $limit + r config set maxmemory-policy $policy + # Now add keys until the limit is almost reached. + set numkeys 0 + while 1 { + r setex [randomKey] 10000 x + incr numkeys + if {[s used_memory]+4096 > $limit} { + assert {$numkeys > 10} + break + } + } + # If we add the same number of keys already added again, we + # should still be under the limit. + for {set j 0} {$j < $numkeys} {incr j} { + r setex [randomKey] 10000 x + } + assert {[s used_memory] < ($limit+4096)} + } + } +} + diff --git a/tests/unit/maxmemory.tcl b/tests/unit/maxmemory.tcl index 0f64ddc18..5a82abb97 100644 --- a/tests/unit/maxmemory.tcl +++ b/tests/unit/maxmemory.tcl @@ -240,4 +240,3 @@ test_slave_buffers {slave buffer are counted correctly} 1000000 10 0 1 # test that slave buffer don't induce eviction # test again with fewer (and bigger) commands without pipeline, but with eviction test_slave_buffers "replica buffer don't induce eviction" 100000 100 1 0 - From 4129ed553c5457b4dac7e4fc51431b73db3de257 Mon Sep 17 00:00:00 2001 From: benschermel Date: Wed, 18 Dec 2019 00:47:08 -0500 Subject: [PATCH 2/2] adding flash test Former-commit-id: 879b17c053695ee09562e2ec320e269141e31fdb --- tests/unit/flash.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/flash.tcl b/tests/unit/flash.tcl index aea00dab3..47c8081cd 100644 --- a/tests/unit/flash.tcl +++ b/tests/unit/flash.tcl @@ -1,4 +1,4 @@ -start_server {tags {"flash"} overrides {"storage-provider flash /mnt/tmp"}} { +start_server {tags {"flash"} overrides {"storage-provider flash ./rocks.db"}} { foreach policy { allkeys-random allkeys-lru allkeys-lfu