1# vi:filetype=
2
3use lib 'lib';
4use Test::Nginx::Socket;
5
6#repeat_each(2);
7
8plan tests => repeat_each() * (5 * blocks() + 4);
9
10$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
11
12#master_on();
13no_shuffle();
14
15run_tests();
16
17__DATA__
18
19=== TEST 1: flush all (not using ngx_srcache)
20--- config
21    location /flush {
22        set $memc_cmd 'flush_all';
23        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
24        add_header X-Fetch-Status $srcache_fetch_status;
25        add_header X-Store-Status $srcache_store_status;
26    }
27--- response_headers
28Content-Type: text/plain
29Content-Length: 4
30X-Fetch-Status: BYPASS
31X-Store-Status: BYPASS
32
33--- request
34GET /flush
35--- response_body eval: "OK\r\n"
36
37
38
39=== TEST 2: basic fetch (cache miss)
40--- config
41    location /foo {
42        default_type text/css;
43        srcache_fetch GET /memc $uri;
44        srcache_store PUT /memc $uri;
45
46        content_by_lua '
47            ngx.header["ETag"] = [["abcd1234"]]
48            ngx.header["Last-Modified"] = "Sat, 01 Mar 2014 01:02:38 GMT"
49            ngx.say("hello")
50        ';
51        #echo hello;
52        add_header X-Fetch-Status $srcache_fetch_status;
53        add_header X-Store-Status $srcache_store_status;
54    }
55
56    location /memc {
57        internal;
58
59        set $memc_key $query_string;
60        set $memc_exptime 300;
61        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
62    }
63--- request
64GET /foo
65--- response_headers
66Content-Type: text/css
67Content-Length:
68X-Fetch-Status: MISS
69X-Store-Status: STORE
70Last-Modified: Sat, 01 Mar 2014 01:02:38 GMT
71--- response_body
72hello
73--- wait: 0.1
74--- error_log
75srcache_store: subrequest returned status 201
76--- log_level: debug
77
78
79
80=== TEST 3: basic fetch (cache hit)
81--- config
82    location /foo {
83        default_type text/css;
84        srcache_fetch GET /memc $uri;
85        srcache_store PUT /memc $uri;
86
87        echo world;
88        add_header X-Fetch-Status $srcache_fetch_status;
89        add_header X-Store-Status $srcache_store_status;
90    }
91
92    location /memc {
93        internal;
94
95        set $memc_key $query_string;
96        set $memc_exptime 300;
97        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
98    }
99--- request
100GET /foo
101--- more_headers
102If-None-Match: "abcd1234"
103--- response_headers
104X-Fetch-Status: HIT
105X-Store-Status: BYPASS
106ETag: "abcd1234"
107Last-Modified: Sat, 01 Mar 2014 01:02:38 GMT
108--- response_body:
109--- error_code: 304
110
111
112
113=== TEST 4: flush all (not using ngx_srcache)
114--- config
115    location /flush {
116        set $memc_cmd 'flush_all';
117        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
118        add_header X-Fetch-Status $srcache_fetch_status;
119        add_header X-Store-Status $srcache_store_status;
120    }
121--- response_headers
122Content-Type: text/plain
123Content-Length: 4
124X-Fetch-Status: BYPASS
125X-Store-Status: BYPASS
126
127--- request
128GET /flush
129--- response_body eval: "OK\r\n"
130
131
132
133=== TEST 5: basic fetch (cache miss, 304)
134--- config
135    location /foo {
136        default_type text/css;
137        srcache_fetch GET /memc $uri;
138        srcache_store PUT /memc $uri;
139
140        content_by_lua '
141            ngx.header["ETag"] = [["abcd1234"]]
142            ngx.header["Last-Modified"] = "Sat, 01 Mar 2014 01:02:38 GMT"
143            ngx.say("hello")
144        ';
145        #echo hello;
146        add_header X-Fetch-Status $srcache_fetch_status;
147        add_header X-Store-Status $srcache_store_status;
148    }
149
150    location /memc {
151        internal;
152
153        set $memc_key $query_string;
154        set $memc_exptime 300;
155        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
156    }
157--- request
158GET /foo
159--- more_headers
160If-None-Match: "abcd1234"
161--- response_headers
162Content-Length:
163X-Fetch-Status: MISS
164X-Store-Status: BYPASS
165Last-Modified: Sat, 01 Mar 2014 01:02:38 GMT
166--- response_body:
167--- error_code: 304
168--- wait: 0.1
169--- error_log
170--- log_level: debug
171
172
173
174=== TEST 6: basic fetch (cache hit)
175--- config
176    location /memc {
177        #internal;
178
179        set $memc_key $query_string;
180        set $memc_exptime 300;
181        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
182    }
183--- request
184GET /memc?/foo
185--- response_body_like: 404 Not Found
186--- error_code: 404
187
188