-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngx.process.master_pid #158
Conversation
you need to change the travis config, use your own branch to test. https://github.com/openresty/lua-resty-core/blob/master/.travis.yml#L62 |
t/process-master-pid.t
Outdated
--- request | ||
GET /t | ||
--- response_body_like chop | ||
\d+$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is too loose. We could do better here by comparing the number returned by master_pid()
against the real master pid saved in the nginx pid file.
local process = require "ngx.process" | ||
|
||
local v | ||
local pid = process.master_pid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely wrong. You missed a pair of parentheses after process.master_pid
. Have you actually run this test yourself?
This is another reason why you should make your PR pass the travis ci checks as @membphis suggested ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm not familar with travis ci, I will try to correct it ,thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here is not an error ,because pid
will be called in then next line :
local v = pid()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chronolaw I see, but the pid
function name is indeed confusing. How about using the variable name get_pid
here? So that there could be no ambiguity here.
I have run test in my own nginx 1.13.8+ngx_lua,and I will try to config travis ci after soon. |
I have tried travis-ci build, but I got an error. Then reason is that the And in nginx 1.13.6, this API will return nil for no Would you give me some advise to write the test case? |
I created a new git branch to fit nginx 1.13.6, now
So could you tell my how to write the right |
After some modify, my own test has passed, please see:https://travis-ci.org/chronolaw/lua-resty-core/jobs/324018825 Changes:
|
@chronolaw You can skip the tests for nginx cores older than 1.13.8 with the |
@chronolaw And you should point to your own fork of lua-nginx-module in |
stitch | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not put extra blank lines at the end of the .t
test files. The tool reindex
can automatically format your .t
files:
https://github.com/openresty/openresty-devel-utils/blob/master/reindex
ngx.say(false) | ||
else | ||
local str = f:read("*l") | ||
ngx.say(v == tonumber(str or "0")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of debugging test failures, I think we should also output the actual master pid in the .pid
file in case of comparison failures.
local process = require "ngx.process" | ||
|
||
local v | ||
local pid = process.master_pid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chronolaw I see, but the pid
function name is indeed confusing. How about using the variable name get_pid
here? So that there could be no ambiguity here.
#worker_connections(1014); | ||
#master_process_enabled(1); | ||
#log_level('warn'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add the following line here to enable nginx master process:
master_on();
The test scaffold does not turn on nginx master process by default. Without this line, this test file fails on my side:
t/process-master-pid.t .. 1/12
# Failed test 'TEST 1: ngx.process.master_pid - response_body_like - response is expected (false 69514)'
# at /home/agentzh/git/lua-resty-core/../test-nginx/lib/Test/Nginx/Socket.pm line 1601.
# 'false
# 69514
# '
# doesn't match '(?^s:^true
# \d+$)'
# Failed test 'TEST 1: ngx.process.master_pid - response_body_like - response is expected (false 69514)'
# at /home/agentzh/git/lua-resty-core/../test-nginx/lib/Test/Nginx/Socket.pm line 1601.
# 'false
# 69514
# '
# doesn't match '(?^s:^true
# \d+$)'
# Looks like you failed 2 tests of 12.
t/process-master-pid.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/12 subtests
Test Summary Report
-------------------
t/process-master-pid.t (Wstat: 512 Tests: 12 Failed: 2)
Failed tests: 2, 8
Non-zero exit status: 2
Files=1, Tests=12, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.09 cusr 0.01 csys = 0.11 CPU)
Result: FAIL
v = pid() | ||
end | ||
|
||
local f = io.open(ngx.config.prefix().."/logs/nginx.pid", "r") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: needs spaces around binary operators like ..
.
Also, io.open()
may return an error, better wrap it with an assert()
call.
Merged by fixing the aforementioned issues myself. Thanks! |
Here is the new API
ngx.process.master_pid
, which needs ffi C functionngx_http_lua_ffi_master_pid
in ngx_lua.I also write a test case in
t/process-master-pid.t
, But I am not familar with Perl and have not found the detail API documents of test::nginx, so I just copiedworker.t
then modified on it.That test case may has error, please help me to correct it. Thanks very much.