|
| 1 | +# vi:ft= |
| 2 | + |
| 3 | +use lib 'lib'; |
| 4 | +use Test::Nginx::Socket; |
| 5 | + |
| 6 | +#repeat_each(2); |
| 7 | + |
| 8 | +plan tests => repeat_each() * 5 * blocks(); |
| 9 | + |
| 10 | +$ENV{TEST_NGINX_REDIS_PORT} ||= 6379; |
| 11 | + |
| 12 | +#master_on(); |
| 13 | +#no_long_string(); |
| 14 | +no_shuffle(); |
| 15 | + |
| 16 | +run_tests(); |
| 17 | + |
| 18 | +__DATA__ |
| 19 | +
|
| 20 | +=== TEST 1: flush all |
| 21 | +--- config |
| 22 | + location /flush { |
| 23 | + redis2_query flushall; |
| 24 | + redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; |
| 25 | + } |
| 26 | +--- response_headers |
| 27 | +Content-Type: text/plain |
| 28 | +!Content-Length |
| 29 | +--- request |
| 30 | +GET /flush |
| 31 | +--- response_body eval: "+OK\r\n" |
| 32 | +--- no_error_log |
| 33 | +[error] |
| 34 | +
|
| 35 | +
|
| 36 | +
|
| 37 | +=== TEST 2: basic fetch (cache miss) |
| 38 | +--- timeout: 3 |
| 39 | +--- config |
| 40 | + location /foo { |
| 41 | + default_type text/css; |
| 42 | +
|
| 43 | + set $key $uri; |
| 44 | + set_escape_uri $escaped_key $key; |
| 45 | + srcache_fetch GET /redis $key; |
| 46 | + srcache_store POST /redis2 key=$escaped_key&exptime=120; |
| 47 | +
|
| 48 | + echo hello; |
| 49 | + echo hiya; |
| 50 | + } |
| 51 | +
|
| 52 | + location = /redis { |
| 53 | + internal; |
| 54 | +
|
| 55 | + set $redis_key $args; |
| 56 | + redis_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; |
| 57 | + } |
| 58 | +
|
| 59 | + location = /redis2 { |
| 60 | + internal; |
| 61 | +
|
| 62 | + set_unescape_uri $exptime $arg_exptime; |
| 63 | + set_unescape_uri $key $arg_key; |
| 64 | +
|
| 65 | + redis2_query set $key $echo_request_body; |
| 66 | + redis2_query expire $key $exptime; |
| 67 | + redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; |
| 68 | + } |
| 69 | +--- request |
| 70 | +GET /foo |
| 71 | +--- response_headers |
| 72 | +Content-Type: text/css |
| 73 | +!Content-Length |
| 74 | +--- response_body |
| 75 | +hello |
| 76 | +hiya |
| 77 | +--- no_error_log |
| 78 | +[error] |
| 79 | +
|
| 80 | +
|
| 81 | +
|
| 82 | +=== TEST 3: basic fetch (cache hit) |
| 83 | +--- config |
| 84 | + location /foo { |
| 85 | + default_type text/css; |
| 86 | +
|
| 87 | + set $key $uri; |
| 88 | + srcache_fetch GET /redis $key; |
| 89 | + srcache_store PUT /redis2 key=$key&exptime=10; |
| 90 | +
|
| 91 | + echo world; |
| 92 | + } |
| 93 | +
|
| 94 | + location = /redis { |
| 95 | + #internal; |
| 96 | +
|
| 97 | + #redis2_query get $args; |
| 98 | + #redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; |
| 99 | + #echo "args = $args"; |
| 100 | +
|
| 101 | + set $redis_key $args; |
| 102 | + redis_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; |
| 103 | + } |
| 104 | +
|
| 105 | + location = /redis2 { |
| 106 | + internal; |
| 107 | +
|
| 108 | + set_unescape_uri $exptime $arg_exptime; |
| 109 | + set_unescape_uri $key $arg_key; |
| 110 | +
|
| 111 | + redis2_query set $key $echo_request_body; |
| 112 | + redis2_query expire $key $exptime; |
| 113 | +
|
| 114 | + redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT; |
| 115 | + } |
| 116 | +--- request |
| 117 | +GET /foo |
| 118 | +--- response_headers |
| 119 | +Content-Type: text/css |
| 120 | +Content-Length: 11 |
| 121 | +--- response_body |
| 122 | +hello |
| 123 | +hiya |
| 124 | +--- no_error_log |
| 125 | +[error] |
| 126 | +
|
0 commit comments