diff options
author | antirez <antirez@gmail.com> | 2013-03-27 11:29:47 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-03-27 11:29:47 +0100 |
commit | 7572dc47da38f5527472935f1f7289fab9c0703f (patch) | |
tree | 1257b492341a64c95dc0a94573f4dd2e95859b7f /tests | |
parent | 4fa30b781ea31a9f0d3d509438190ed5cea8b981 (diff) | |
download | redis-7572dc47da38f5527472935f1f7289fab9c0703f.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 62b08bed3..3e1c55b2f 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. |