|
1 | 1 | use Test::Nginx::Socket::Lua; |
2 | 2 | use Cwd qw(cwd); |
3 | 3 |
|
4 | | -repeat_each(2); |
5 | | - |
6 | | -plan tests => repeat_each() * (3 * blocks()); |
| 4 | +plan tests => repeat_each() * (3 * blocks() - 1); |
7 | 5 |
|
8 | 6 | my $pwd = cwd(); |
9 | 7 |
|
@@ -181,3 +179,36 @@ null |
181 | 179 | an animal |
182 | 180 | --- no_error_log |
183 | 181 | [error] |
| 182 | + |
| 183 | + |
| 184 | +=== TEST 5: Test set_keepalive method |
| 185 | +--- http_config eval: $::HttpConfig |
| 186 | +--- config |
| 187 | +location /t { |
| 188 | + lua_socket_log_errors Off; |
| 189 | + content_by_lua_block { |
| 190 | + local rc = require("resty.redis.connector").new() |
| 191 | + |
| 192 | + local redis = assert(rc:connect(), |
| 193 | + "rc:connect should return positively") |
| 194 | + local ok, err = rc:set_keepalive(redis) |
| 195 | + assert(not err, "set_keepalive error should be nil") |
| 196 | + |
| 197 | + local ok, err = redis:set("foo", "bar") |
| 198 | + assert(not ok, "ok should be nil") |
| 199 | + assert(string.find(err, "closed"), "error should contain 'closed'") |
| 200 | + |
| 201 | + local redis = assert(rc:connect(), "connect should return positively") |
| 202 | + assert(redis:subscribe("channel"), "subscribe should return positively") |
| 203 | + |
| 204 | + local ok, err = rc:set_keepalive(redis) |
| 205 | + assert(not ok, "ok should be nil") |
| 206 | + assert(string.find(err, "subscribed state"), |
| 207 | + "error should contain 'subscribed state'") |
| 208 | + |
| 209 | + } |
| 210 | +} |
| 211 | +--- request |
| 212 | +GET /t |
| 213 | +--- no_error_log |
| 214 | +[error] |
0 commit comments