diff --git a/tests/integration/replication.tcl b/tests/integration/replication.tcl index 9bad9cbe..ae1977dc 100644 --- a/tests/integration/replication.tcl +++ b/tests/integration/replication.tcl @@ -94,15 +94,6 @@ start_server {tags {"repl"}} { } } -proc start_write_load {host port seconds} { - set tclsh [info nameofexecutable] - exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds & -} - -proc stop_write_load {handle} { - catch {exec /bin/kill -9 $handle} -} - start_server {tags {"repl"}} { set master [srv 0 client] set master_host [srv 0 host] diff --git a/tests/support/util.tcl b/tests/support/util.tcl index 8ef6e1bc..7774dd99 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -359,3 +359,15 @@ proc colorstr {color str} { return $str } } + +# Execute a background process writing random data for the specified number +# of seconds to the specified Redis instance. +proc start_write_load {host port seconds} { + set tclsh [info nameofexecutable] + exec $tclsh tests/helpers/gen_write_load.tcl $host $port $seconds & +} + +# Stop a process generating write load executed with start_write_load. +proc stop_write_load {handle} { + catch {exec /bin/kill -9 $handle} +} diff --git a/tests/unit/aofrw.tcl b/tests/unit/aofrw.tcl index e651694f..1c61ea56 100644 --- a/tests/unit/aofrw.tcl +++ b/tests/unit/aofrw.tcl @@ -1,5 +1,57 @@ start_server {tags {"aofrw"}} { + # Enable the AOF + r config set appendonly yes + r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite. + waitForBgrewriteaof r + test {AOF rewrite during write load} { + # Start a write load for 10 seconds + set master [srv 0 client] + set master_host [srv 0 host] + set master_port [srv 0 port] + set load_handle0 [start_write_load $master_host $master_port 10] + set load_handle1 [start_write_load $master_host $master_port 10] + set load_handle2 [start_write_load $master_host $master_port 10] + set load_handle3 [start_write_load $master_host $master_port 10] + set load_handle4 [start_write_load $master_host $master_port 10] + + # Make sure the instance is really receiving data + wait_for_condition 50 100 { + [r dbsize] > 0 + } else { + fail "No write load detected." + } + + # After 3 seconds, start a rewrite, while the write load is still + # active. + after 3000 + r bgrewriteaof + waitForBgrewriteaof r + + # Let it run a bit more so that we'll append some data to the new + # AOF. + after 1000 + + # Stop the processes generating the load if they are still active + stop_write_load $load_handle0 + stop_write_load $load_handle1 + stop_write_load $load_handle2 + stop_write_load $load_handle3 + stop_write_load $load_handle4 + + # Get the data set digest + set d1 [r debug digest] + + # Load the AOF + r debug loadaof + set d2 [r debug digest] + + # Make sure they are the same + assert {$d1 eq $d2} + } +} + +start_server {tags {"aofrw"}} { test {Turning off AOF kills the background writing child if any} { r config set appendonly yes waitForBgrewriteaof r