/
135-worker-id.t
93 lines (80 loc) · 1.93 KB
/
135-worker-id.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# vim:set ft= ts=4 sw=4 et fdm=marker:
use Test::Nginx::Socket::Lua;
#worker_connections(1014);
master_on();
workers(2);
#log_level('warn');
#repeat_each(2);
plan tests => repeat_each() * (blocks() * 3 + 1);
#no_diff();
#no_long_string();
run_tests();
__DATA__
=== TEST 1: sanity
--- config
location /lua {
content_by_lua_block {
ngx.say("worker id: ", ngx.worker.id())
}
}
--- request
GET /lua
--- response_body_like chop
^worker id: [0-1]$
--- no_error_log
[error]
--- skip_nginx: 3: <=1.9.0
=== TEST 2: worker id should be nil for non-worker processes
--- http_config
proxy_cache_path conf/cache levels=1:2 keys_zone=my-cache:8m max_size=10m inactive=60m;
proxy_temp_path conf/temp;
lua_shared_dict counters 1m;
init_by_lua_block {
ngx.shared.counters:set("c", 0)
}
init_worker_by_lua_block {
ngx.shared.counters:incr("c", 1)
ngx.log(ngx.INFO, ngx.worker.pid(), ": worker id ", ngx.worker.id());
}
--- config
location = /t {
content_by_lua_block {
local counters = ngx.shared.counters
local ok, c
for i = 1, 45 do
c = counters:get("c")
if c >= 4 then
ok = true
break
end
local delay = 0.001 * i
if delay > 0.1 then
delay = 0.1
end
ngx.sleep(delay)
end
if ok then
ngx.say("ok")
else
ngx.say("not ok: c=", c)
end
}
}
location /cache {
proxy_pass http://127.0.0.1:$server_port;
proxy_cache my-cache;
}
--- request
GET /t
--- response_body
ok
--- grep_error_log eval: qr/worker id nil/
--- grep_error_log_out
worker id nil
worker id nil
--- no_error_log
[error]
--- wait: 0.1
--- skip_nginx: 3: <=1.9.0
--- log_level: info
--- timeout: 6