diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl index 5ea2b9cd1..95f18b086 100644 --- a/tests/unit/type/list.tcl +++ b/tests/unit/type/list.tcl @@ -1,3 +1,11 @@ +proc wait_for_blocked_client {} { + wait_for_condition 50 100 { + [s blocked_clients] ne 0 + } else { + fail "no blocked clients" + } +} + start_server { tags {"list"} overrides { @@ -52,7 +60,7 @@ start_server { test {LPOS when RANK is greater than matches} { r DEL mylist - r LPUSH l a + r LPUSH mylist a assert {[r LPOS mylist b COUNT 10 RANK 5] eq {}} } @@ -217,6 +225,8 @@ start_server { r del list $rd blpop list 0 + after 100 ;# Make sure rd is blocked before MULTI + r multi r lpush list a r del list @@ -887,4 +897,45 @@ start_server { $rd2 close r ping } {PONG} + + test "client unblock tests" { + r del l + set rd [redis_deferring_client] + $rd client id + set id [$rd read] + + # test default args + $rd blpop l 0 + wait_for_blocked_client + r client unblock $id + assert_equal {} [$rd read] + + # test with timeout + $rd blpop l 0 + wait_for_blocked_client + r client unblock $id TIMEOUT + assert_equal {} [$rd read] + + # test with error + $rd blpop l 0 + wait_for_blocked_client + r client unblock $id ERROR + catch {[$rd read]} e + assert_equal $e "UNBLOCKED client unblocked via CLIENT UNBLOCK" + + # test with invalid client id + catch {[r client unblock asd]} e + assert_equal $e "ERR value is not an integer or out of range" + + # test with non blocked client + set myid [r client id] + catch {[r client unblock $myid]} e + assert_equal $e {invalid command name "0"} + + # finally, see the this client and list are still functional + $rd blpop l 0 + wait_for_blocked_client + r lpush l foo + assert_equal {l foo} [$rd read] + } {} }