feature: added new API function ngx.worker.exiting() for testing if the current worker process is exiting.

This commit is contained in:
Yichun Zhang (agentzh) 2013-11-23 20:32:43 -08:00
Родитель 4d6dc5804a
Коммит 002b68ec75
6 изменённых файлов: 95 добавлений и 1 удалений

2
config
Просмотреть файл

@ -223,6 +223,7 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
$ngx_addon_dir/src/ngx_http_lua_uthread.c \
$ngx_addon_dir/src/ngx_http_lua_timer.c \
$ngx_addon_dir/src/ngx_http_lua_config.c \
$ngx_addon_dir/src/ngx_http_lua_worker.c \
"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
@ -274,6 +275,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ngx_addon_dir/src/ngx_http_lua_uthread.h \
$ngx_addon_dir/src/ngx_http_lua_timer.h \
$ngx_addon_dir/src/ngx_http_lua_config.h \
$ngx_addon_dir/src/ngx_http_lua_worker.h \
"
CFLAGS="$CFLAGS -DNDK_SET_VAR"

Просмотреть файл

@ -47,6 +47,7 @@
#include "ngx_http_lua_contentby.h"
#include "ngx_http_lua_timer.h"
#include "ngx_http_lua_config.h"
#include "ngx_http_lua_worker.h"
#if 1
@ -786,6 +787,7 @@ ngx_http_lua_inject_ngx_api(ngx_conf_t *cf, lua_State *L)
ngx_http_lua_inject_uthread_api(cf->log, L);
ngx_http_lua_inject_timer_api(L);
ngx_http_lua_inject_config_api(L);
ngx_http_lua_inject_worker_api(L);
ngx_http_lua_inject_misc_api(L);

36
src/ngx_http_lua_worker.c Normal file
Просмотреть файл

@ -0,0 +1,36 @@
/*
* Copyright (C) Yichun Zhang (agentzh)
*/
#ifndef DDEBUG
#define DDEBUG 0
#endif
#include "ddebug.h"
#include "ngx_http_lua_worker.h"
static int ngx_http_lua_ngx_worker_exiting(lua_State *L);
void
ngx_http_lua_inject_worker_api(lua_State *L)
{
lua_createtable(L, 0 /* narr */, 1 /* nrec */); /* ngx.timer. */
lua_pushcfunction(L, ngx_http_lua_ngx_worker_exiting);
lua_setfield(L, -2, "exiting");
lua_setfield(L, -2, "worker");
}
static int
ngx_http_lua_ngx_worker_exiting(lua_State *L)
{
lua_pushboolean(L, ngx_exiting);
return 1;
}

17
src/ngx_http_lua_worker.h Normal file
Просмотреть файл

@ -0,0 +1,17 @@
/*
* Copyright (C) Yichun Zhang (agentzh)
*/
#ifndef _NGX_HTTP_LUA_WORKER_H_INCLUDED_
#define _NGX_HTTP_LUA_WORKER_H_INCLUDED_
#include "ngx_http_lua_common.h"
void ngx_http_lua_inject_worker_api(lua_State *L);
#endif /* _NGX_HTTP_LUA_WORKER_H_INCLUDED_ */

Просмотреть файл

@ -28,7 +28,7 @@ our $StapScript = $t::StapThread::StapScript;
repeat_each(2);
plan tests => repeat_each() * 59;
plan tests => repeat_each() * 61;
#no_diff();
no_long_string();
@ -233,10 +233,12 @@ failed to register a new timer after reload: process exiting, context: ngx.timer
local function g(premature)
print("g: timer prematurely expired: ", premature)
print("g: exiting=", ngx.worker.exiting())
end
local function f(premature)
print("f: timer prematurely expired: ", premature)
print("f: exiting=", ngx.worker.exiting())
local ok, err = ngx.timer.at(0, g)
if not ok then
print("f: failed to register a new timer after reload: ", err)
@ -274,5 +276,7 @@ lua ngx.timer expired
http lua close fake http connection
f: timer prematurely expired: true
f: registered a new timer after reload
f: exiting=true
g: timer prematurely expired: true
g: exiting=true

33
t/122-worker.t Normal file
Просмотреть файл

@ -0,0 +1,33 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:
use t::TestNginxLua;
#worker_connections(1014);
#master_on();
#workers(2);
#log_level('warn');
repeat_each(2);
plan tests => repeat_each() * (blocks() * 3);
#no_diff();
no_long_string();
run_tests();
__DATA__
=== TEST 1: content_by_lua
--- config
location /lua {
content_by_lua '
ngx.say("worker exiting: ", ngx.worker.exiting())
';
}
--- request
GET /lua
--- response_body
worker exiting: false
--- no_error_log
[error]