diff options
author | antirez <antirez@gmail.com> | 2013-03-27 11:29:47 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-03-27 12:05:15 +0100 |
commit | 7009ff98b86cfecd4100f67e2835558e4380df01 (patch) | |
tree | 45c92047a11c1454c88d7935bdc78e9cf0eb283c /tests | |
parent | a452b548497925164757e1309e1caadfaded95a3 (diff) | |
download | redis-7009ff98b86cfecd4100f67e2835558e4380df01.tar.gz |
Test: new functions to capture and analyze the replication stream.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_helper.tcl | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 483774219..6aeff6ac2 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -408,6 +408,59 @@ for {set j 0} {$j < [llength $argv]} {incr j} { } } +proc attach_to_replication_stream {} { + set s [socket [srv 0 "host"] [srv 0 "port"]] + fconfigure $s -translation binary + puts -nonewline $s "SYNC\r\n" + flush $s + + # Get the count + set count [gets $s] + set prefix [string range $count 0 0] + if {$prefix ne {$}} { + error "attach_to_replication_stream error. Received '$count' as count." + } + set count [string range $count 1 end] + + # Consume the bulk payload + while {$count} { + set buf [read $s $count] + set count [expr {$count-[string length $buf]}] + } + return $s +} + +proc read_from_replication_stream {s} { + fconfigure $s -blocking 0 + set attempt 0 + while {[gets $s count] == -1} { + if {[incr attempt] == 10} return "" + after 100 + } + fconfigure $s -blocking 1 + set count [string range $count 1 end] + + # Return a list of arguments for the command. + set res {} + for {set j 0} {$j < $count} {incr j} { + read $s 1 + set arg [::redis::redis_bulk_read $s] + if {$j == 0} {set arg [string tolower $arg]} + lappend res $arg + } + return $res +} + +proc assert_replication_stream {s patterns} { + for {set j 0} {$j < [llength $patterns]} {incr j} { + assert_match [lindex $patterns $j] [read_from_replication_stream $s] + } +} + +proc close_replication_stream {s} { + close $s +} + # With the parallel test running multiple Redis instances at the same time # we need a fast enough computer, otherwise a lot of tests may generate # false positives. |