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
073a42b9
Commit
073a42b9
authored
Oct 30, 2015
by
antirez
Browse files
Scripting: execute tests with command replication as well.
parent
ff6d2960
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/unit/scripting.tcl
View file @
073a42b9
...
@@ -521,94 +521,103 @@ start_server {tags {"scripting"}} {
...
@@ -521,94 +521,103 @@ start_server {tags {"scripting"}} {
}
}
}
}
start_server
{
tags
{
"scripting repl"
}}
{
foreach cmdrepl
{
0 1
}
{
start_server
{}
{
start_server
{
tags
{
"scripting repl"
}}
{
test
{
Before the slave connects we issue two EVAL commands
}
{
start_server
{}
{
# One with an error, but still executing a command.
if
{
$cmdrepl
== 1
}
{
# SHA is: 67164fc43fa971f76fd1aaeeaf60c1c178d25876
set rt
"(commmands replication)"
catch
{
r eval
{
redis.call
(
'incr',KEYS
[
1
]);
redis.call
(
'nonexisting'
)}
1 x
}
# One command is correct:
# SHA is: 6f5ade10a69975e903c6d07b10ea44c6382381a5
r eval
{
return redis.call
(
'incr',KEYS
[
1
])}
1 x
}
{
2
}
test
{
Connect a slave to the main instance
}
{
r -1 slaveof
[
srv 0 host
]
[
srv 0 port
]
wait_for_condition 50 100
{
[
s -1 role
]
eq
{
slave
}
&&
[
string match
{
*master_link_status:up*
}
[
r -1 info replication
]]
}
else
{
}
else
{
fail
"Can't turn the instance into a slave"
set rt
"(scripts replication)"
r debug lua-always-replicate-commands 1
}
}
}
test
{
Now use EVALSHA against the master, with both SHAs
}
{
test
"Before the slave connects we issue two EVAL commands
$rt
"
{
# The server should replicate successful and unsuccessful
# One with an error, but still executing a command.
# commands as EVAL instead of EVALSHA.
# SHA is: 67164fc43fa971f76fd1aaeeaf60c1c178d25876
catch
{
catch
{
r evalsha 67164fc43fa971f76fd1aaeeaf60c1c178d25876 1 x
r eval
{
redis.call
(
'incr',KEYS
[
1
]);
redis.call
(
'nonexisting'
)}
1 x
}
# One command is correct:
# SHA is: 6f5ade10a69975e903c6d07b10ea44c6382381a5
r eval
{
return redis.call
(
'incr',KEYS
[
1
])}
1 x
}
{
2
}
test
"Connect a slave to the main instance
$rt
"
{
r -1 slaveof
[
srv 0 host
]
[
srv 0 port
]
wait_for_condition 50 100
{
[
s -1 role
]
eq
{
slave
}
&&
[
string match
{
*master_link_status:up*
}
[
r -1 info replication
]]
}
else
{
fail
"Can't turn the instance into a slave"
}
}
}
r evalsha 6f5ade10a69975e903c6d07b10ea44c6382381a5 1 x
}
{
4
}
test
{
If EVALSHA was replicated as EVAL, 'x' should be '4'
}
{
test
"Now use EVALSHA against the master, with both SHAs
$rt
"
{
wait_for_condition 50 100
{
# The server should replicate successful and unsuccessful
[
r -1 get x
]
eq
{
4
}
# commands as EVAL instead of EVALSHA.
}
else
{
catch
{
fail
"Expected 4 in x, but value is '
[
r -1 get x
]
'"
r evalsha 67164fc43fa971f76fd1aaeeaf60c1c178d25876 1 x
}
r evalsha 6f5ade10a69975e903c6d07b10ea44c6382381a5 1 x
}
{
4
}
test
"If EVALSHA was replicated as EVAL, 'x' should be '4'
$rt
"
{
wait_for_condition 50 100
{
[
r -1 get x
]
eq
{
4
}
}
else
{
fail
"Expected 4 in x, but value is '
[
r -1 get x
]
'"
}
}
}
}
test
{
Replication of script multiple pushes to list with BLPOP
}
{
test
"Replication of script multiple pushes to list with BLPOP
$rt
"
{
set rd
[
redis_deferring_client
]
set rd
[
redis_deferring_client
]
$rd brpop a 0
$rd brpop a 0
r eval
{
r eval
{
redis.call
(
"lpush"
,KEYS
[
1
]
,
"1"
);
redis.call
(
"lpush"
,KEYS
[
1
]
,
"1"
);
redis.call
(
"lpush"
,KEYS
[
1
]
,
"2"
);
redis.call
(
"lpush"
,KEYS
[
1
]
,
"2"
);
}
1 a
}
1 a
set res
[
$rd
read
]
set res
[
$rd
read
]
$rd close
$rd close
wait_for_condition 50 100
{
wait_for_condition 50 100
{
[
r -1 lrange a 0 -1
]
eq
[
r lrange a 0 -1
]
[
r -1 lrange a 0 -1
]
eq
[
r lrange a 0 -1
]
}
else
{
}
else
{
fail
"Expected list 'a' in slave and master to be the same, but they are respectively '
[
r -1 lrange a 0 -1
]
' and '
[
r lrange a 0 -1
]
'"
fail
"Expected list 'a' in slave and master to be the same, but they are respectively '
[
r -1 lrange a 0 -1
]
' and '
[
r lrange a 0 -1
]
'"
}
}
set res
set res
}
{
a 1
}
}
{
a 1
}
test
{
EVALSHA replication when first call is readonly
}
{
test
"EVALSHA replication when first call is readonly
$rt
"
{
r del x
r del x
r eval
{
if tonumber
(
ARGV
[
1
])
> 0 then redis.call
(
'incr', KEYS
[
1
])
end
}
1 x 0
r eval
{
if tonumber
(
ARGV
[
1
])
> 0 then redis.call
(
'incr', KEYS
[
1
])
end
}
1 x 0
r evalsha 6e0e2745aa546d0b50b801a20983b70710aef3ce 1 x 0
r evalsha 6e0e2745aa546d0b50b801a20983b70710aef3ce 1 x 0
r evalsha 6e0e2745aa546d0b50b801a20983b70710aef3ce 1 x 1
r evalsha 6e0e2745aa546d0b50b801a20983b70710aef3ce 1 x 1
wait_for_condition 50 100
{
wait_for_condition 50 100
{
[
r -1 get x
]
eq
{
1
}
[
r -1 get x
]
eq
{
1
}
}
else
{
}
else
{
fail
"Expected 1 in x, but value is '
[
r -1 get x
]
'"
fail
"Expected 1 in x, but value is '
[
r -1 get x
]
'"
}
}
}
}
test
{
Lua scripts using SELECT are replicated correctly
}
{
test
"Lua scripts using SELECT are replicated correctly
$rt
"
{
r eval
{
r eval
{
redis.call
(
"set"
,
"foo1"
,
"bar1"
)
redis.call
(
"set"
,
"foo1"
,
"bar1"
)
redis.call
(
"select"
,
"10"
)
redis.call
(
"select"
,
"10"
)
redis.call
(
"incr"
,
"x"
)
redis.call
(
"incr"
,
"x"
)
redis.call
(
"select"
,
"11"
)
redis.call
(
"select"
,
"11"
)
redis.call
(
"incr"
,
"z"
)
redis.call
(
"incr"
,
"z"
)
}
0
}
0
r eval
{
r eval
{
redis.call
(
"set"
,
"foo1"
,
"bar1"
)
redis.call
(
"set"
,
"foo1"
,
"bar1"
)
redis.call
(
"select"
,
"10"
)
redis.call
(
"select"
,
"10"
)
redis.call
(
"incr"
,
"x"
)
redis.call
(
"incr"
,
"x"
)
redis.call
(
"select"
,
"11"
)
redis.call
(
"select"
,
"11"
)
redis.call
(
"incr"
,
"z"
)
redis.call
(
"incr"
,
"z"
)
}
0
}
0
wait_for_condition 50 100
{
wait_for_condition 50 100
{
[
r -1 debug digest
]
eq
[
r debug digest
]
[
r -1 debug digest
]
eq
[
r debug digest
]
}
else
{
}
else
{
fail
"Master-Slave desync after Lua script using SELECT."
fail
"Master-Slave desync after Lua script using SELECT."
}
}
}
}
}
}
}
...
...
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