Skip to content

Instantly share code, notes, and snippets.

@felipou
Last active August 25, 2020 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipou/acd4469dffbfe02740dfe7465ee60b72 to your computer and use it in GitHub Desktop.
Save felipou/acd4469dffbfe02740dfe7465ee60b72 to your computer and use it in GitHub Desktop.
# Existing tests
test "BRPOPLPUSH with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd brpoplpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
assert_equal foo [$rd read]
assert_equal {foo bar} [r lrange target 0 -1]
}
test "BRPOPRPUSH with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd brpoprpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
assert_equal foo [$rd read]
assert_equal {bar foo} [r lrange target 0 -1]
}
test "BLPOPLPUSH with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd blpoplpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
assert_equal foo [$rd read]
assert_equal {foo bar} [r lrange target 0 -1]
}
test "BLPOPRPUSH with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd blpoprpush blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
assert_equal foo [$rd read]
assert_equal {bar foo} [r lrange target 0 -1]
}
# Option 1
foreach popdir {r l} {
foreach {pushdir a b} {r bar foo l foo bar} {
set cmd b${popdir}pop${pushdir}push
test "[string toupper $cmd] with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd $cmd blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
assert_equal foo [$rd read]
assert_equal "$a $b" [r lrange target 0 -1]
}
}
}
# Option 2
foreach {cmd a b} {brpoplpush foo bar brpoprpush bar foo blpoplpush foo bar blpoprpush bar foo} {
test "[string toupper $cmd] with zero timeout should block indefinitely" {
set rd [redis_deferring_client]
r del blist target
r rpush target bar
$rd $cmd blist target 0
wait_for_condition 100 10 {
[s blocked_clients] == 1
} else {
fail "Timeout waiting for blocked clients"
}
r rpush blist foo
assert_equal foo [$rd read]
assert_equal "$a $b" [r lrange target 0 -1]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment