Skip to content

Commit 17fd14c

Browse files
committed
remove test case to a seperate file
1 parent 2a2e332 commit 17fd14c

File tree

2 files changed

+204
-186
lines changed

2 files changed

+204
-186
lines changed

t/043-shdict.t

Lines changed: 0 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,189 +2397,3 @@ type: table
23972397
--- no_error_log
23982398
[error]
23992399

2400-
2401-
2402-
=== TEST 91: incr key with init (key exists)
2403-
--- http_config
2404-
lua_shared_dict dogs 1m;
2405-
--- config
2406-
location = /test {
2407-
content_by_lua '
2408-
local dogs = ngx.shared.dogs
2409-
dogs:set("foo", 32)
2410-
local res, err = dogs:incr("foo", 10502, 1)
2411-
ngx.say("incr: ", res, " ", err)
2412-
ngx.say("foo = ", dogs:get("foo"))
2413-
';
2414-
}
2415-
--- request
2416-
GET /test
2417-
--- response_body
2418-
incr: 10534 nil
2419-
foo = 10534
2420-
--- no_error_log
2421-
[error]
2422-
2423-
2424-
2425-
=== TEST 92: incr key with init (key not exists)
2426-
--- http_config
2427-
lua_shared_dict dogs 1m;
2428-
--- config
2429-
location = /test {
2430-
content_by_lua '
2431-
local dogs = ngx.shared.dogs
2432-
dogs:set("bah", 32)
2433-
local res, err = dogs:incr("foo", 10502, 1)
2434-
ngx.say("incr: ", res, " ", err)
2435-
ngx.say("foo = ", dogs:get("foo"))
2436-
';
2437-
}
2438-
--- request
2439-
GET /test
2440-
--- response_body
2441-
incr: 10503 nil
2442-
foo = 10503
2443-
--- no_error_log
2444-
[error]
2445-
2446-
2447-
2448-
=== TEST 93: incr key with init (key expired and size not matched)
2449-
--- http_config
2450-
lua_shared_dict dogs 1m;
2451-
--- config
2452-
location = /test {
2453-
content_by_lua '
2454-
local dogs = ngx.shared.dogs
2455-
for i = 1, 20 do
2456-
dogs:set("bar" .. i, i, 0.001)
2457-
end
2458-
dogs:set("foo", "32", 0.001)
2459-
ngx.location.capture("/sleep/0.002")
2460-
local res, err = dogs:incr("foo", 10502, 0)
2461-
ngx.say("incr: ", res, " ", err)
2462-
ngx.say("foo = ", dogs:get("foo"))
2463-
';
2464-
}
2465-
location ~ ^/sleep/(.+) {
2466-
echo_sleep $1;
2467-
}
2468-
--- request
2469-
GET /test
2470-
--- response_body
2471-
incr: 10502 nil
2472-
foo = 10502
2473-
--- no_error_log
2474-
[error]
2475-
2476-
2477-
2478-
=== TEST 94: incr key with init (key expired and size matched)
2479-
--- http_config
2480-
lua_shared_dict dogs 1m;
2481-
--- config
2482-
location = /test {
2483-
content_by_lua '
2484-
local dogs = ngx.shared.dogs
2485-
for i = 1, 20 do
2486-
dogs:set("bar" .. i, i, 0.001)
2487-
end
2488-
dogs:set("foo", 32, 0.001)
2489-
ngx.location.capture("/sleep/0.002")
2490-
local res, err = dogs:incr("foo", 10502, 0)
2491-
ngx.say("incr: ", res, " ", err)
2492-
ngx.say("foo = ", dogs:get("foo"))
2493-
';
2494-
}
2495-
location ~ ^/sleep/(.+) {
2496-
echo_sleep $1;
2497-
}
2498-
--- request
2499-
GET /test
2500-
--- response_body
2501-
incr: 10502 nil
2502-
foo = 10502
2503-
--- no_error_log
2504-
[error]
2505-
2506-
2507-
2508-
=== TEST 95: incr key with init (forcibly override other valid entries)
2509-
--- http_config
2510-
lua_shared_dict dogs 1m;
2511-
--- config
2512-
location = /test {
2513-
content_by_lua '
2514-
local dogs = ngx.shared.dogs
2515-
dogs:flush_all()
2516-
local long_prefix = string.rep("1234567890", 100)
2517-
for i = 1, 1000 do
2518-
local success, err, forcible = dogs:set(long_prefix .. i, i)
2519-
if forcible then
2520-
dogs:delete(long_prefix .. i)
2521-
break
2522-
end
2523-
end
2524-
local res, err, forcible = dogs:incr(long_prefix .. "bar", 10502, 0)
2525-
ngx.say("incr: ", res, " ", err, " ", forcible)
2526-
local res, err, forcible = dogs:incr(long_prefix .. "foo", 10502, 0)
2527-
ngx.say("incr: ", res, " ", err, " ", forcible)
2528-
ngx.say("foo = ", dogs:get(long_prefix .. "foo"))
2529-
';
2530-
}
2531-
--- request
2532-
GET /test
2533-
--- response_body
2534-
incr: 10502 nil false
2535-
incr: 10502 nil true
2536-
foo = 10502
2537-
--- no_error_log
2538-
[error]
2539-
2540-
2541-
2542-
=== TEST 96: incr key without init (no forcible returned)
2543-
--- http_config
2544-
lua_shared_dict dogs 1m;
2545-
--- config
2546-
location = /test {
2547-
content_by_lua '
2548-
local dogs = ngx.shared.dogs
2549-
dogs:set("foo", 1)
2550-
local res, err, forcible = dogs:incr("foo", 1)
2551-
ngx.say("incr: ", res, " ", err, " ", forcible)
2552-
ngx.say("foo = ", dogs:get("foo"))
2553-
';
2554-
}
2555-
--- request
2556-
GET /test
2557-
--- response_body
2558-
incr: 2 nil nil
2559-
foo = 2
2560-
--- no_error_log
2561-
[error]
2562-
2563-
2564-
2565-
=== TEST 97: incr key (original value is not number)
2566-
--- http_config
2567-
lua_shared_dict dogs 1m;
2568-
--- config
2569-
location = /test {
2570-
content_by_lua '
2571-
local dogs = ngx.shared.dogs
2572-
dogs:set("foo", true)
2573-
local res, err = dogs:incr("foo", 1, 0)
2574-
ngx.say("incr: ", res, " ", err)
2575-
ngx.say("foo = ", dogs:get("foo"))
2576-
';
2577-
}
2578-
--- request
2579-
GET /test
2580-
--- response_body
2581-
incr: nil not a number
2582-
foo = true
2583-
--- no_error_log
2584-
[error]
2585-

t/133-shdict-incr-init.t

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# vim:set ft= ts=4 sw=4 et fdm=marker:
2+
use lib 'lib';
3+
use Test::Nginx::Socket::Lua;
4+
5+
#worker_connections(1014);
6+
#master_process_enabled(1);
7+
#log_level('warn');
8+
9+
#repeat_each(2);
10+
11+
plan tests => repeat_each() * (blocks() * 3 + 0);
12+
13+
#no_diff();
14+
no_long_string();
15+
#master_on();
16+
#workers(2);
17+
18+
run_tests();
19+
20+
__DATA__
21+
22+
=== TEST 1: incr key with init (key exists)
23+
--- http_config
24+
lua_shared_dict dogs 1m;
25+
--- config
26+
location = /test {
27+
content_by_lua '
28+
local dogs = ngx.shared.dogs
29+
dogs:set("foo", 32)
30+
local res, err = dogs:incr("foo", 10502, 1)
31+
ngx.say("incr: ", res, " ", err)
32+
ngx.say("foo = ", dogs:get("foo"))
33+
';
34+
}
35+
--- request
36+
GET /test
37+
--- response_body
38+
incr: 10534 nil
39+
foo = 10534
40+
--- no_error_log
41+
[error]
42+
43+
44+
45+
=== TEST 2: incr key with init (key not exists)
46+
--- http_config
47+
lua_shared_dict dogs 1m;
48+
--- config
49+
location = /test {
50+
content_by_lua '
51+
local dogs = ngx.shared.dogs
52+
dogs:set("bah", 32)
53+
local res, err = dogs:incr("foo", 10502, 1)
54+
ngx.say("incr: ", res, " ", err)
55+
ngx.say("foo = ", dogs:get("foo"))
56+
';
57+
}
58+
--- request
59+
GET /test
60+
--- response_body
61+
incr: 10503 nil
62+
foo = 10503
63+
--- no_error_log
64+
[error]
65+
66+
67+
68+
=== TEST 3: incr key with init (key expired and size not matched)
69+
--- http_config
70+
lua_shared_dict dogs 1m;
71+
--- config
72+
location = /test {
73+
content_by_lua '
74+
local dogs = ngx.shared.dogs
75+
for i = 1, 20 do
76+
dogs:set("bar" .. i, i, 0.001)
77+
end
78+
dogs:set("foo", "32", 0.001)
79+
ngx.location.capture("/sleep/0.002")
80+
local res, err = dogs:incr("foo", 10502, 0)
81+
ngx.say("incr: ", res, " ", err)
82+
ngx.say("foo = ", dogs:get("foo"))
83+
';
84+
}
85+
location ~ ^/sleep/(.+) {
86+
echo_sleep $1;
87+
}
88+
--- request
89+
GET /test
90+
--- response_body
91+
incr: 10502 nil
92+
foo = 10502
93+
--- no_error_log
94+
[error]
95+
96+
97+
98+
=== TEST 4: incr key with init (key expired and size matched)
99+
--- http_config
100+
lua_shared_dict dogs 1m;
101+
--- config
102+
location = /test {
103+
content_by_lua '
104+
local dogs = ngx.shared.dogs
105+
for i = 1, 20 do
106+
dogs:set("bar" .. i, i, 0.001)
107+
end
108+
dogs:set("foo", 32, 0.001)
109+
ngx.location.capture("/sleep/0.002")
110+
local res, err = dogs:incr("foo", 10502, 0)
111+
ngx.say("incr: ", res, " ", err)
112+
ngx.say("foo = ", dogs:get("foo"))
113+
';
114+
}
115+
location ~ ^/sleep/(.+) {
116+
echo_sleep $1;
117+
}
118+
--- request
119+
GET /test
120+
--- response_body
121+
incr: 10502 nil
122+
foo = 10502
123+
--- no_error_log
124+
[error]
125+
126+
127+
128+
=== TEST 5: incr key with init (forcibly override other valid entries)
129+
--- http_config
130+
lua_shared_dict dogs 1m;
131+
--- config
132+
location = /test {
133+
content_by_lua '
134+
local dogs = ngx.shared.dogs
135+
dogs:flush_all()
136+
local long_prefix = string.rep("1234567890", 100)
137+
for i = 1, 1000 do
138+
local success, err, forcible = dogs:set(long_prefix .. i, i)
139+
if forcible then
140+
dogs:delete(long_prefix .. i)
141+
break
142+
end
143+
end
144+
local res, err, forcible = dogs:incr(long_prefix .. "bar", 10502, 0)
145+
ngx.say("incr: ", res, " ", err, " ", forcible)
146+
local res, err, forcible = dogs:incr(long_prefix .. "foo", 10502, 0)
147+
ngx.say("incr: ", res, " ", err, " ", forcible)
148+
ngx.say("foo = ", dogs:get(long_prefix .. "foo"))
149+
';
150+
}
151+
--- request
152+
GET /test
153+
--- response_body
154+
incr: 10502 nil false
155+
incr: 10502 nil true
156+
foo = 10502
157+
--- no_error_log
158+
[error]
159+
160+
161+
162+
=== TEST 6: incr key without init (no forcible returned)
163+
--- http_config
164+
lua_shared_dict dogs 1m;
165+
--- config
166+
location = /test {
167+
content_by_lua '
168+
local dogs = ngx.shared.dogs
169+
dogs:set("foo", 1)
170+
local res, err, forcible = dogs:incr("foo", 1)
171+
ngx.say("incr: ", res, " ", err, " ", forcible)
172+
ngx.say("foo = ", dogs:get("foo"))
173+
';
174+
}
175+
--- request
176+
GET /test
177+
--- response_body
178+
incr: 2 nil nil
179+
foo = 2
180+
--- no_error_log
181+
[error]
182+
183+
184+
185+
=== TEST 7: incr key (original value is not number)
186+
--- http_config
187+
lua_shared_dict dogs 1m;
188+
--- config
189+
location = /test {
190+
content_by_lua '
191+
local dogs = ngx.shared.dogs
192+
dogs:set("foo", true)
193+
local res, err = dogs:incr("foo", 1, 0)
194+
ngx.say("incr: ", res, " ", err)
195+
ngx.say("foo = ", dogs:get("foo"))
196+
';
197+
}
198+
--- request
199+
GET /test
200+
--- response_body
201+
incr: nil not a number
202+
foo = true
203+
--- no_error_log
204+
[error]

0 commit comments

Comments
 (0)