test-nginx测试用例(exit_worker_by_lua*功能)

158 views
Skip to first unread message

xianlian...@gmail.com

unread,
Jan 3, 2017, 6:00:12 AM1/3/17
to openresty
 hi,all。
 我今天早上向ngx_lua pull request exit_worker_by_lua*功能。但我昨天在测试用例(151_exit-worker.t)时遇到一些问题。
 exit_worker_by_lua*阶段是在process worker exit阶段才会执行,即相关信息需在worker exit阶段才会输出。但test-nginx中grep_error_log貌似是在request请求之中和之后才会去grep error log。
在使用Test::Nginx wait还是不能解决;所以我现在自己用grep来确认测试用例的(见图)。不知道大家有没有好的解决方案。
 现在测试用例是这么写的。(见附件)


151-exit-worker.t

xianlian...@gmail.com

unread,
Jan 3, 2017, 6:11:18 AM1/3/17
to openresty
lua-nginx-module pull request为https://github.com/openresty/lua-nginx-module/pull/927

在 2017年1月3日星期二 UTC+8下午7:00:12,xianlian...@gmail.com写道:

YuanSheng Wang

unread,
Jan 4, 2017, 7:05:52 AM1/4/17
to open...@googlegroups.com, DeJiang Zhu
hi

翻看 Test::Nginx::Socket.pm 和 Test::Nginx::Util.pm 源码,发现最后的错误日志分析 check_error_log 是接口测试完毕之后立刻检测的。

但你这里的目标却是 worker 进程退出后对 error.log 进行检测,所以导致错误日志没有匹配到。

对 Test::Nginx::Socket 添加新的指令,比如:stop_after_request ,这样我们就可以在请求完毕后主动关闭 nginx 进程,
然后调用 check_error_log 就可以过滤到我们想要的日志了。

不过 stop_after_request 和 repeat_each 指令是相互冲突的,所以代码中还需要对这种情况进行校验和异常报错。

这样是否合理?如果没有更好的办法,我就提交一个 PR 添加对这种情况的覆盖。 @agentzh @德江 


--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html



--

YuanSheng Wang
---------------------------------------
OpenResty lover ^_^

YuanSheng Wang

unread,
Jan 4, 2017, 10:27:59 PM1/4/17
to open...@googlegroups.com
hi:

按照上文所说,我尝试修改了一个版本: https://github.com/iresty/test-nginx ,可以尝试用这个版本实验一下。

使用方法见下面例子:

=== TEST 1: simple exit_worker_by_lua_block
--- http_config
    exit_worker_by_lua_block {
        ngx.log(ngx.ERR, "log from exit_worker_by_lua_block")
    }
--- config
    location /t {
        echo "ok";
    }
--- request
GET /t
--- response_body
ok
--- stop_after_request
--- error_log
log from exit_worker_by_lua_block



xianlian...@gmail.com

unread,
Jan 5, 2017, 9:37:05 PM1/5/17
to openresty
好的,感谢。

在 2017年1月5日星期四 UTC+8上午11:27:59,YuanSheng写道:
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
--

YuanSheng Wang
---------------------------------------
OpenResty lover ^_^

xianlian...@gmail.com

unread,
Jan 5, 2017, 10:25:00 PM1/5/17
to openresty
你好我clone  https://github.com/iresty/test-nginx去跑测试用例(按照你给定的修改),还是通不过。你确认下你的修改是否提交到 https://github.com/iresty/test-nginx;我没看到你最近的提交记录。

在 2017年1月6日星期五 UTC+8上午10:37:05,xianlian...@gmail.com写道:

xianlian...@gmail.com

unread,
Jan 5, 2017, 11:36:43 PM1/5/17
to openresty
hi,测试通过了,一开始没看到有feature/add_stop_after_request。

在 2017年1月6日星期五 UTC+8上午11:25:00,xianlian...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages