aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/moduleapi/blockonbackground.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/blockonbackground.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/moduleapi/blockonbackground.tcl124
1 files changed, 0 insertions, 124 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/blockonbackground.tcl b/examples/redis-unstable/tests/unit/moduleapi/blockonbackground.tcl
deleted file mode 100644
index e8b9f55..0000000
--- a/examples/redis-unstable/tests/unit/moduleapi/blockonbackground.tcl
+++ /dev/null
@@ -1,124 +0,0 @@
1set testmodule [file normalize tests/modules/blockonbackground.so]
2
3proc latency_percentiles_usec {cmd} {
4 return [latencyrstat_percentiles $cmd r]
5}
6
7start_server {tags {"modules external:skip"}} {
8 r module load $testmodule
9
10 test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time} {
11 r slowlog reset
12 r config set slowlog-log-slower-than 200000
13 if {!$::no_latency} {
14 assert_equal [r slowlog len] 0
15 }
16 r block.debug 0 10000
17 if {!$::no_latency} {
18 assert_equal [r slowlog len] 0
19 }
20 r config resetstat
21 r config set latency-tracking yes
22 r config set latency-tracking-info-percentiles "50.0"
23 r block.debug 200 10000
24 if {!$::no_latency} {
25 assert_equal [r slowlog len] 1
26 }
27
28 set cmdstatline [cmdrstat block.debug r]
29 set latencystatline_debug [latency_percentiles_usec block.debug]
30
31 regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline -> usec usec_per_call
32 regexp "p50=(.+\..+)" $latencystatline_debug -> p50
33 assert {$usec >= 100000}
34 assert {$usec_per_call >= 100000}
35 assert {$p50 >= 100000}
36 }
37
38 test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time even in timeout } {
39 r slowlog reset
40 r config set slowlog-log-slower-than 200000
41 if {!$::no_latency} {
42 assert_equal [r slowlog len] 0
43 }
44 r block.debug 0 20000
45 if {!$::no_latency} {
46 assert_equal [r slowlog len] 0
47 }
48 r config resetstat
49 r block.debug 20000 500
50 if {!$::no_latency} {
51 assert_equal [r slowlog len] 1
52 }
53
54 set cmdstatline [cmdrstat block.debug r]
55
56 regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
57 assert {$usec >= 250000}
58 assert {$usec_per_call >= 250000}
59 }
60
61 test { blocked clients time tracking - check blocked command with multiple calls RedisModule_BlockedClientMeasureTimeStart() is tracking the total background time } {
62 r slowlog reset
63 r config set slowlog-log-slower-than 200000
64 if {!$::no_latency} {
65 assert_equal [r slowlog len] 0
66 }
67 r block.double_debug 0
68 if {!$::no_latency} {
69 assert_equal [r slowlog len] 0
70 }
71 r config resetstat
72 r block.double_debug 100
73 if {!$::no_latency} {
74 assert_equal [r slowlog len] 1
75 }
76 set cmdstatline [cmdrstat block.double_debug r]
77
78 regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
79 assert {$usec >= 60000}
80 assert {$usec_per_call >= 60000}
81 }
82
83 test { blocked clients time tracking - check blocked command without calling RedisModule_BlockedClientMeasureTimeStart() is not reporting background time } {
84 r slowlog reset
85 r config set slowlog-log-slower-than 200000
86 if {!$::no_latency} {
87 assert_equal [r slowlog len] 0
88 }
89 r block.debug_no_track 200 1000
90 # ensure slowlog is still empty
91 if {!$::no_latency} {
92 assert_equal [r slowlog len] 0
93 }
94 }
95
96 test "client unblock works only for modules with timeout support" {
97 set rd [redis_deferring_client]
98 $rd client id
99 set id [$rd read]
100
101 # Block with a timeout function - may unblock
102 $rd block.block 20000
103 wait_for_condition 50 100 {
104 [r block.is_blocked] == 1
105 } else {
106 fail "Module did not block"
107 }
108
109 assert_equal 1 [r client unblock $id]
110 assert_match {*Timed out*} [$rd read]
111
112 # Block without a timeout function - cannot unblock
113 $rd block.block 0
114 wait_for_condition 50 100 {
115 [r block.is_blocked] == 1
116 } else {
117 fail "Module did not block"
118 }
119
120 assert_equal 0 [r client unblock $id]
121 assert_equal "OK" [r block.release foobar]
122 assert_equal "foobar" [$rd read]
123 }
124}