diff options
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/postnotifications.tcl')
| -rw-r--r-- | examples/redis-unstable/tests/unit/moduleapi/postnotifications.tcl | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/postnotifications.tcl b/examples/redis-unstable/tests/unit/moduleapi/postnotifications.tcl new file mode 100644 index 0000000..31a4669 --- /dev/null +++ b/examples/redis-unstable/tests/unit/moduleapi/postnotifications.tcl | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | set testmodule [file normalize tests/modules/postnotifications.so] | ||
| 2 | |||
| 3 | tags "modules external:skip" { | ||
| 4 | start_server {} { | ||
| 5 | r module load $testmodule with_key_events | ||
| 6 | |||
| 7 | test {Test write on post notification callback} { | ||
| 8 | set repl [attach_to_replication_stream] | ||
| 9 | |||
| 10 | r set string_x 1 | ||
| 11 | assert_equal {1} [r get string_changed{string_x}] | ||
| 12 | assert_equal {1} [r get string_total] | ||
| 13 | |||
| 14 | r set string_x 2 | ||
| 15 | assert_equal {2} [r get string_changed{string_x}] | ||
| 16 | assert_equal {2} [r get string_total] | ||
| 17 | |||
| 18 | # the {lpush before_overwritten string_x} is a post notification job registered when 'string_x' was overwritten | ||
| 19 | assert_replication_stream $repl { | ||
| 20 | {multi} | ||
| 21 | {select *} | ||
| 22 | {set string_x 1} | ||
| 23 | {incr string_changed{string_x}} | ||
| 24 | {incr string_total} | ||
| 25 | {exec} | ||
| 26 | {multi} | ||
| 27 | {set string_x 2} | ||
| 28 | {lpush before_overwritten string_x} | ||
| 29 | {incr string_changed{string_x}} | ||
| 30 | {incr string_total} | ||
| 31 | {exec} | ||
| 32 | } | ||
| 33 | close_replication_stream $repl | ||
| 34 | } | ||
| 35 | |||
| 36 | test {Test write on post notification callback from module thread} { | ||
| 37 | r flushall | ||
| 38 | set repl [attach_to_replication_stream] | ||
| 39 | |||
| 40 | assert_equal {OK} [r postnotification.async_set] | ||
| 41 | assert_equal {1} [r get string_changed{string_x}] | ||
| 42 | assert_equal {1} [r get string_total] | ||
| 43 | |||
| 44 | assert_replication_stream $repl { | ||
| 45 | {multi} | ||
| 46 | {select *} | ||
| 47 | {set string_x 1} | ||
| 48 | {incr string_changed{string_x}} | ||
| 49 | {incr string_total} | ||
| 50 | {exec} | ||
| 51 | } | ||
| 52 | close_replication_stream $repl | ||
| 53 | } | ||
| 54 | |||
| 55 | test {Test active expire} { | ||
| 56 | r flushall | ||
| 57 | set repl [attach_to_replication_stream] | ||
| 58 | |||
| 59 | r set x 1 | ||
| 60 | r pexpire x 10 | ||
| 61 | |||
| 62 | wait_for_condition 100 50 { | ||
| 63 | [r keys expired] == {expired} | ||
| 64 | } else { | ||
| 65 | puts [r keys *] | ||
| 66 | fail "Failed waiting for x to expired" | ||
| 67 | } | ||
| 68 | |||
| 69 | # the {lpush before_expired x} is a post notification job registered before 'x' got expired | ||
| 70 | assert_replication_stream $repl { | ||
| 71 | {select *} | ||
| 72 | {set x 1} | ||
| 73 | {pexpireat x *} | ||
| 74 | {multi} | ||
| 75 | {del x} | ||
| 76 | {lpush before_expired x} | ||
| 77 | {incr expired} | ||
| 78 | {exec} | ||
| 79 | } | ||
| 80 | close_replication_stream $repl | ||
| 81 | } | ||
| 82 | |||
| 83 | test {Test lazy expire} { | ||
| 84 | r flushall | ||
| 85 | r DEBUG SET-ACTIVE-EXPIRE 0 | ||
| 86 | set repl [attach_to_replication_stream] | ||
| 87 | |||
| 88 | r set x 1 | ||
| 89 | r pexpire x 1 | ||
| 90 | after 10 | ||
| 91 | assert_equal {} [r get x] | ||
| 92 | |||
| 93 | # the {lpush before_expired x} is a post notification job registered before 'x' got expired | ||
| 94 | assert_replication_stream $repl { | ||
| 95 | {select *} | ||
| 96 | {set x 1} | ||
| 97 | {pexpireat x *} | ||
| 98 | {multi} | ||
| 99 | {del x} | ||
| 100 | {lpush before_expired x} | ||
| 101 | {incr expired} | ||
| 102 | {exec} | ||
| 103 | } | ||
| 104 | close_replication_stream $repl | ||
| 105 | r DEBUG SET-ACTIVE-EXPIRE 1 | ||
| 106 | } {OK} {needs:debug} | ||
| 107 | |||
| 108 | test {Test lazy expire inside post job notification} { | ||
| 109 | r flushall | ||
| 110 | r DEBUG SET-ACTIVE-EXPIRE 0 | ||
| 111 | set repl [attach_to_replication_stream] | ||
| 112 | |||
| 113 | r set x 1 | ||
| 114 | r pexpire x 1 | ||
| 115 | after 10 | ||
| 116 | assert_equal {OK} [r set read_x 1] | ||
| 117 | |||
| 118 | # the {lpush before_expired x} is a post notification job registered before 'x' got expired | ||
| 119 | assert_replication_stream $repl { | ||
| 120 | {select *} | ||
| 121 | {set x 1} | ||
| 122 | {pexpireat x *} | ||
| 123 | {multi} | ||
| 124 | {set read_x 1} | ||
| 125 | {del x} | ||
| 126 | {lpush before_expired x} | ||
| 127 | {incr expired} | ||
| 128 | {exec} | ||
| 129 | } | ||
| 130 | close_replication_stream $repl | ||
| 131 | r DEBUG SET-ACTIVE-EXPIRE 1 | ||
| 132 | } {OK} {needs:debug} | ||
| 133 | |||
| 134 | test {Test nested keyspace notification} { | ||
| 135 | r flushall | ||
| 136 | set repl [attach_to_replication_stream] | ||
| 137 | |||
| 138 | assert_equal {OK} [r set write_sync_write_sync_x 1] | ||
| 139 | |||
| 140 | assert_replication_stream $repl { | ||
| 141 | {multi} | ||
| 142 | {select *} | ||
| 143 | {set x 1} | ||
| 144 | {set write_sync_x 1} | ||
| 145 | {set write_sync_write_sync_x 1} | ||
| 146 | {exec} | ||
| 147 | } | ||
| 148 | close_replication_stream $repl | ||
| 149 | } | ||
| 150 | |||
| 151 | test {Test eviction} { | ||
| 152 | r flushall | ||
| 153 | set repl [attach_to_replication_stream] | ||
| 154 | r set x 1 | ||
| 155 | r config set maxmemory-policy allkeys-random | ||
| 156 | r config set maxmemory 1 | ||
| 157 | |||
| 158 | assert_error {OOM *} {r set y 1} | ||
| 159 | |||
| 160 | # the {lpush before_evicted x} is a post notification job registered before 'x' got evicted | ||
| 161 | assert_replication_stream $repl { | ||
| 162 | {select *} | ||
| 163 | {set x 1} | ||
| 164 | {multi} | ||
| 165 | {del x} | ||
| 166 | {lpush before_evicted x} | ||
| 167 | {incr evicted} | ||
| 168 | {exec} | ||
| 169 | } | ||
| 170 | close_replication_stream $repl | ||
| 171 | } {} {needs:config-maxmemory} | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | set testmodule2 [file normalize tests/modules/keyspace_events.so] | ||
| 176 | |||
| 177 | tags "modules external:skip" { | ||
| 178 | start_server {} { | ||
| 179 | r module load $testmodule with_key_events | ||
| 180 | r module load $testmodule2 | ||
| 181 | test {Test write on post notification callback} { | ||
| 182 | set repl [attach_to_replication_stream] | ||
| 183 | |||
| 184 | r set string_x 1 | ||
| 185 | assert_equal {1} [r get string_changed{string_x}] | ||
| 186 | assert_equal {1} [r get string_total] | ||
| 187 | |||
| 188 | r set string_x 2 | ||
| 189 | assert_equal {2} [r get string_changed{string_x}] | ||
| 190 | assert_equal {2} [r get string_total] | ||
| 191 | |||
| 192 | r set string1_x 1 | ||
| 193 | assert_equal {1} [r get string_changed{string1_x}] | ||
| 194 | assert_equal {3} [r get string_total] | ||
| 195 | |||
| 196 | # the {lpush before_overwritten string_x} is a post notification job registered before 'string_x' got overwritten | ||
| 197 | assert_replication_stream $repl { | ||
| 198 | {multi} | ||
| 199 | {select *} | ||
| 200 | {set string_x 1} | ||
| 201 | {incr string_changed{string_x}} | ||
| 202 | {incr string_total} | ||
| 203 | {exec} | ||
| 204 | {multi} | ||
| 205 | {set string_x 2} | ||
| 206 | {lpush before_overwritten string_x} | ||
| 207 | {incr string_changed{string_x}} | ||
| 208 | {incr string_total} | ||
| 209 | {exec} | ||
| 210 | {multi} | ||
| 211 | {set string1_x 1} | ||
| 212 | {incr string_changed{string1_x}} | ||
| 213 | {incr string_total} | ||
| 214 | {exec} | ||
| 215 | } | ||
| 216 | close_replication_stream $repl | ||
| 217 | } | ||
| 218 | } | ||
| 219 | } | ||
