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
4589a823
Commit
4589a823
authored
Jun 15, 2010
by
Pieter Noordhuis
Browse files
initial basic pub/sub tests
parent
676740a9
Changes
3
Show whitespace changes
Inline
Side-by-side
tests/support/redis.tcl
View file @
4589a823
...
...
@@ -41,7 +41,7 @@ array set ::redis::multibulkarg {}
# Flag commands requiring last argument as a bulk write operation
foreach redis_bulk_cmd
{
set setnx rpush lpush rpushx lpushx linsert lset lrem sadd srem sismember echo getset smove zadd zrem zscore zincrby append zrank zrevrank hget hdel hexists setex
set setnx rpush lpush rpushx lpushx linsert lset lrem sadd srem sismember echo getset smove zadd zrem zscore zincrby append zrank zrevrank hget hdel hexists setex
publish
}
{
set ::redis::bulkarg
(
$redis
_bulk_cmd
)
{}
}
...
...
tests/test_helper.tcl
View file @
4589a823
...
...
@@ -88,6 +88,7 @@ proc main {} {
execute_tests
"unit/cas"
execute_tests
"integration/replication"
execute_tests
"integration/aof"
execute_tests
"unit/pubsub"
# run tests with VM enabled
set ::global_overrides
{
vm-enabled yes
}
...
...
tests/unit/pubsub.tcl
0 → 100644
View file @
4589a823
start_server
{
tags
{
"pubsub"
}}
{
test
"PUBLISH when no one is listening"
{
assert_equal 0
[
r publish chan hello
]
}
test
"SUBSCRIBE basics"
{
set rd1
[
redis_deferring_client
]
set rd2
[
redis_deferring_client
]
# subscribe first client to two channels
$rd1 subscribe chan1 chan2
assert_equal
{
subscribe chan1 1
}
[
$rd1
read
]
assert_equal
{
subscribe chan2 2
}
[
$rd1
read
]
# publish on both channels
assert_equal 1
[
r publish chan1 hello
]
assert_equal 1
[
r publish chan2 world
]
assert_equal
{
message chan1 hello
}
[
$rd1
read
]
assert_equal
{
message chan2 world
}
[
$rd1
read
]
# subscribe second client to one channel
$rd2 subscribe chan1
assert_equal
{
subscribe chan1 1
}
[
$rd2
read
]
# publish on channel with two subscribers
assert_equal 2
[
r publish chan1 hello
]
assert_equal
{
message chan1 hello
}
[
$rd1
read
]
assert_equal
{
message chan1 hello
}
[
$rd2
read
]
# unsubscribe first client from all channels
$rd1 unsubscribe
set msg
[
$rd1
read
]
assert_equal
"unsubscribe"
[
lindex $msg 0
]
assert_match
"chan*"
[
lindex $msg 1
]
assert_match 1
[
lindex $msg 2
]
set msg
[
$rd1
read
]
assert_equal
"unsubscribe"
[
lindex $msg 0
]
assert_match
"chan*"
[
lindex $msg 1
]
assert_match 0
[
lindex $msg 2
]
# publish on channel with only remaining subscriber
assert_equal 1
[
r publish chan1 hello
]
assert_equal
{
message chan1 hello
}
[
$rd2
read
]
}
}
\ No newline at end of file
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