Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
7572dc47
Commit
7572dc47
authored
Mar 27, 2013
by
antirez
Browse files
Test: new functions to capture and analyze the replication stream.
parent
4fa30b78
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_helper.tcl
View file @
7572dc47
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment