|
| 1 | +# vim:set ft= ts=4 sw=4 et fdm=marker: |
| 2 | + |
| 3 | +use lib '.'; |
| 4 | +use t::TestCore; |
| 5 | + |
| 6 | +master_process_enabled(1); |
| 7 | + |
| 8 | +repeat_each(1); |
| 9 | + |
| 10 | +plan tests => repeat_each() * (blocks() * 5); |
| 11 | + |
| 12 | + |
| 13 | +$ENV{TEST_NGINX_LUA_PACKAGE_PATH} = $t::TestCore::lua_package_path; |
| 14 | +$ENV{TEST_NGINX_RANDOM_PORT} = Test::Nginx::Util::server_port(); |
| 15 | + |
| 16 | +run_tests(); |
| 17 | + |
| 18 | +__DATA__ |
| 19 | + |
| 20 | +=== TEST 1: specify connections to enable_privileged_agent |
| 21 | +--- http_config |
| 22 | + lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 23 | + |
| 24 | + init_by_lua_block { |
| 25 | + local process = require "ngx.process" |
| 26 | + local ok, err = process.enable_privileged_agent(10) |
| 27 | + if not ok then |
| 28 | + ngx.log(ngx.ERR, "enable_privileged_agent failed: ", err) |
| 29 | + end |
| 30 | + } |
| 31 | + |
| 32 | + init_worker_by_lua_block { |
| 33 | + local base = require "resty.core.base" |
| 34 | + local typ = (require "ngx.process").type() |
| 35 | + |
| 36 | + if typ == "privileged agent" then |
| 37 | + ngx.log(ngx.WARN, "process type: ", typ) |
| 38 | + ngx.timer.at(0, function() |
| 39 | + local tcpsock = ngx.socket.tcp() |
| 40 | + local ok, err = tcpsock:connect("127.0.0.1", $TEST_NGINX_RANDOM_PORT) |
| 41 | + |
| 42 | + if ok then |
| 43 | + ngx.log(ngx.INFO, "connect ok ") |
| 44 | + else |
| 45 | + ngx.log(ngx.INFO, "connect failed " .. tostring(err)) |
| 46 | + end |
| 47 | + end) |
| 48 | + end |
| 49 | + } |
| 50 | +--- config |
| 51 | + location = /t { |
| 52 | + content_by_lua_block { |
| 53 | + ngx.sleep(0.1) |
| 54 | + local typ = require "ngx.process".type() |
| 55 | + ngx.say("type: ", typ) |
| 56 | + } |
| 57 | + } |
| 58 | +--- request |
| 59 | +GET /t |
| 60 | +--- response_body |
| 61 | +type: worker |
| 62 | +--- error_log |
| 63 | +connect ok |
| 64 | +--- no_error_log |
| 65 | +connect failed |
| 66 | +enable_privileged_agent failed |
| 67 | +--- skip_nginx: 5: < 1.11.2 |
| 68 | +--- wait: 0.2 |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +=== TEST 2: connections exceed limit |
| 73 | +the real connections you can create is always less than you set. |
| 74 | +timer will take fake connections. |
| 75 | +--- http_config |
| 76 | + lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 77 | + |
| 78 | + init_by_lua_block { |
| 79 | + local process = require "ngx.process" |
| 80 | + local ok, err = process.enable_privileged_agent(10) |
| 81 | + if not ok then |
| 82 | + ngx.log(ngx.ERR, "enable_privileged_agent failed: ", err) |
| 83 | + end |
| 84 | + } |
| 85 | + |
| 86 | + init_worker_by_lua_block { |
| 87 | + local base = require "resty.core.base" |
| 88 | + local typ = (require "ngx.process").type() |
| 89 | + |
| 90 | + if typ == "privileged agent" then |
| 91 | + ngx.log(ngx.WARN, "process type: ", typ) |
| 92 | + |
| 93 | + ngx.timer.at(0, function() |
| 94 | + |
| 95 | + for i = 1, 10 do |
| 96 | + local tcpsock = ngx.socket.tcp() |
| 97 | + local ok, err = tcpsock:connect("127.0.0.1", $TEST_NGINX_RANDOM_PORT) |
| 98 | + |
| 99 | + if ok then |
| 100 | + ngx.log(ngx.INFO, "connect ok ") |
| 101 | + else |
| 102 | + ngx.log(ngx.INFO, "connect failed " .. tostring(err)) |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + end) |
| 107 | + end |
| 108 | + } |
| 109 | +--- config |
| 110 | + location = /t { |
| 111 | + content_by_lua_block { |
| 112 | + ngx.sleep(0.1) |
| 113 | + local typ = require "ngx.process".type() |
| 114 | + ngx.say("type: ", typ) |
| 115 | + } |
| 116 | + } |
| 117 | +--- request |
| 118 | +GET /t |
| 119 | +--- response_body |
| 120 | +type: worker |
| 121 | +--- error_log |
| 122 | +connect failed |
| 123 | +worker_connections are not enough |
| 124 | +--- no_error_log |
| 125 | +enable_privileged_agent failed |
| 126 | +--- skip_nginx: 5: < 1.11.2 |
| 127 | +--- wait: 0.2 |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +=== TEST 3: enable_privileged_agent with bad connections |
| 132 | +connections < 0 |
| 133 | +--- http_config |
| 134 | + lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 135 | + |
| 136 | + init_by_lua_block { |
| 137 | + local process = require "ngx.process" |
| 138 | + local ok, err = process.enable_privileged_agent(-1) |
| 139 | + if not ok then |
| 140 | + ngx.log(ngx.ERR, "enable_privileged_agent failed: ", err) |
| 141 | + end |
| 142 | + } |
| 143 | + |
| 144 | + init_worker_by_lua_block { |
| 145 | + local base = require "resty.core.base" |
| 146 | + local typ = (require "ngx.process").type() |
| 147 | + |
| 148 | + if typ == "privileged agent" then |
| 149 | + ngx.log(ngx.WARN, "process type: ", typ) |
| 150 | + |
| 151 | + ngx.timer.at(0, function() |
| 152 | + |
| 153 | + for i = 1, 10 do |
| 154 | + local tcpsock = ngx.socket.tcp() |
| 155 | + local ok, err = tcpsock:connect("127.0.0.1", $TEST_NGINX_RANDOM_PORT) |
| 156 | + |
| 157 | + if ok then |
| 158 | + ngx.log(ngx.INFO, "connect ok ") |
| 159 | + else |
| 160 | + ngx.log(ngx.INFO, "connect failed " .. tostring(err)) |
| 161 | + end |
| 162 | + end |
| 163 | + |
| 164 | + end) |
| 165 | + end |
| 166 | + } |
| 167 | +--- config |
| 168 | + location = /t { |
| 169 | + content_by_lua_block { |
| 170 | + ngx.sleep(0.1) |
| 171 | + local typ = require "ngx.process".type() |
| 172 | + ngx.say("type: ", typ) |
| 173 | + } |
| 174 | + } |
| 175 | +--- request |
| 176 | +GET /t |
| 177 | +--- response_body |
| 178 | +type: worker |
| 179 | +--- error_log |
| 180 | +enable_privileged_agent failed: bad 'connections' argument |
| 181 | +--- no_error_log |
| 182 | +connect ok |
| 183 | +connect failed |
| 184 | +--- skip_nginx: 5: < 1.11.2 |
| 185 | +--- wait: 0.2 |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | +=== TEST 4: enable_privileged_agent with bad connections |
| 190 | +connections is not a number |
| 191 | +--- http_config |
| 192 | + lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 193 | + |
| 194 | + init_by_lua_block { |
| 195 | + local process = require "ngx.process" |
| 196 | + local ok, err = process.enable_privileged_agent("10") |
| 197 | + if not ok then |
| 198 | + ngx.log(ngx.ERR, "enable_privileged_agent failed: ", err) |
| 199 | + end |
| 200 | + } |
| 201 | + |
| 202 | + init_worker_by_lua_block { |
| 203 | + local base = require "resty.core.base" |
| 204 | + local typ = (require "ngx.process").type() |
| 205 | + |
| 206 | + if typ == "privileged agent" then |
| 207 | + ngx.log(ngx.WARN, "process type: ", typ) |
| 208 | + |
| 209 | + ngx.timer.at(0, function() |
| 210 | + |
| 211 | + for i = 1, 10 do |
| 212 | + local tcpsock = ngx.socket.tcp() |
| 213 | + local ok, err = tcpsock:connect("127.0.0.1", $TEST_NGINX_RANDOM_PORT) |
| 214 | + |
| 215 | + if ok then |
| 216 | + ngx.log(ngx.INFO, "connect ok ") |
| 217 | + else |
| 218 | + ngx.log(ngx.INFO, "connect failed " .. tostring(err)) |
| 219 | + end |
| 220 | + end |
| 221 | + |
| 222 | + end) |
| 223 | + end |
| 224 | + } |
| 225 | +--- config |
| 226 | + location = /t { |
| 227 | + content_by_lua_block { |
| 228 | + ngx.sleep(0.1) |
| 229 | + local typ = require "ngx.process".type() |
| 230 | + ngx.say("type: ", typ) |
| 231 | + } |
| 232 | + } |
| 233 | +--- request |
| 234 | +GET /t |
| 235 | +--- response_body |
| 236 | +type: worker |
| 237 | +--- error_log |
| 238 | +enable_privileged_agent failed: bad 'connections' argument |
| 239 | +--- no_error_log |
| 240 | +connect ok |
| 241 | +connect failed |
| 242 | +--- skip_nginx: 5: < 1.11.2 |
| 243 | +--- wait: 0.2 |
| 244 | + |
| 245 | + |
| 246 | + |
| 247 | +=== TEST 5: enable_privileged_agent with bad connections |
| 248 | +connections = 0 |
| 249 | +--- http_config |
| 250 | + lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; |
| 251 | + |
| 252 | + init_by_lua_block { |
| 253 | + local process = require "ngx.process" |
| 254 | + local ok, err = process.enable_privileged_agent(0) |
| 255 | + if not ok then |
| 256 | + ngx.log(ngx.ERR, "enable_privileged_agent failed: ", err) |
| 257 | + end |
| 258 | + } |
| 259 | + |
| 260 | + init_worker_by_lua_block { |
| 261 | + local base = require "resty.core.base" |
| 262 | + local typ = (require "ngx.process").type() |
| 263 | + |
| 264 | + if typ == "privileged agent" then |
| 265 | + ngx.log(ngx.WARN, "process type: ", typ) |
| 266 | + |
| 267 | + ngx.timer.at(0, function() |
| 268 | + |
| 269 | + for i = 1, 10 do |
| 270 | + local tcpsock = ngx.socket.tcp() |
| 271 | + local ok, err = tcpsock:connect("127.0.0.1", $TEST_NGINX_RANDOM_PORT) |
| 272 | + |
| 273 | + if ok then |
| 274 | + ngx.log(ngx.INFO, "connect ok ") |
| 275 | + else |
| 276 | + ngx.log(ngx.INFO, "connect failed " .. tostring(err)) |
| 277 | + end |
| 278 | + end |
| 279 | + |
| 280 | + end) |
| 281 | + end |
| 282 | + } |
| 283 | +--- config |
| 284 | + location = /t { |
| 285 | + content_by_lua_block { |
| 286 | + ngx.sleep(0.1) |
| 287 | + local typ = require "ngx.process".type() |
| 288 | + ngx.say("type: ", typ) |
| 289 | + } |
| 290 | + } |
| 291 | +--- request |
| 292 | +GET /t |
| 293 | +--- response_body |
| 294 | +type: worker |
| 295 | +--- grep_error_log eval |
| 296 | +qr/privileged agent process \d+ exited with fatal code 2 and cannot be respawned/ |
| 297 | +--- grep_error_log_out eval |
| 298 | +qr/privileged agent process \d+ exited with fatal code 2 and cannot be respawned/ |
| 299 | +--- no_error_log |
| 300 | +process type: privileged agent |
| 301 | +connect ok |
| 302 | +--- skip_nginx: 5: < 1.11.2 |
| 303 | +--- wait: 0.2 |
0 commit comments