From 1ff2dea44d0281a16c7f6c911a1f7fa147ed5d60 Mon Sep 17 00:00:00 2001 From: splitice Date: Mon, 28 Dec 2015 22:51:10 +1100 Subject: [PATCH 01/11] shared dictionary incr method exptime added to FFI api --- lib/resty/core/shdict.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/resty/core/shdict.lua b/lib/resty/core/shdict.lua index de811ae47..e7ab5cadd 100644 --- a/lib/resty/core/shdict.lua +++ b/lib/resty/core/shdict.lua @@ -26,7 +26,7 @@ ffi.cdef[[ int get_stale, int *is_stale); int ngx_http_lua_ffi_shdict_incr(void *zone, const unsigned char *key, - size_t key_len, double *value, char **err); + size_t key_len, double *value, int exptime, char **err); int ngx_http_lua_ffi_shdict_store(void *zone, int op, const unsigned char *key, size_t key_len, int value_type, @@ -311,7 +311,7 @@ local function shdict_get_stale(zone, key) end -local function shdict_incr(zone, key, value) +local function shdict_incr(zone, key, value, exptime) zone = check_zone(zone) if key == nil then @@ -334,9 +334,11 @@ local function shdict_incr(zone, key, value) value = tonumber(value) end num_value[0] = value + + exptime = exptime or -1 local rc = C.ngx_http_lua_ffi_shdict_incr(zone, key, key_len, num_value, - errmsg) + exptime, errmsg) if rc ~= 0 then -- ~= NGX_OK return nil, ffi_str(errmsg[0]) end From ff6287f9677126ba9b8dabf76804abccc3671a27 Mon Sep 17 00:00:00 2001 From: splitice Date: Mon, 28 Dec 2015 22:52:40 +1100 Subject: [PATCH 02/11] add simple shared dictionary test --- t/shdict.t | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/t/shdict.t b/t/shdict.t index c62e25eaf..3be23f687 100644 --- a/t/shdict.t +++ b/t/shdict.t @@ -915,3 +915,27 @@ qr/\[TRACE \d+ content_by_lua\(nginx\.conf:\d+\):7 loop\]/ -- NYI: stitch + + + +=== TEST 27: incr key expire +--- http_config eval: $::HttpConfig +--- config + location = /t { + content_by_lua ' + local val, flags + local dogs = ngx.shared.dogs + local value, err = dogs:incr(nil, 32, 10) + if not ok then + ngx.say("failed to incr: ", err) + end + '; + } +--- request +GET /t +--- response_body +failed to incr: nil key +--- no_error_log +[error] +[alert] +[crit] \ No newline at end of file From d78c8a3d7030c17c9cc595a6d80bc067552ade6b Mon Sep 17 00:00:00 2001 From: splitice Date: Thu, 4 Feb 2016 19:26:21 +1100 Subject: [PATCH 03/11] initial creation of two balancer modules --- lib/ngx/{balancer.lua => balancer_http.lua} | 0 lib/ngx/balancer_stream.lua | 82 +++++++++++++++++++++ 2 files changed, 82 insertions(+) rename lib/ngx/{balancer.lua => balancer_http.lua} (100%) create mode 100644 lib/ngx/balancer_stream.lua diff --git a/lib/ngx/balancer.lua b/lib/ngx/balancer_http.lua similarity index 100% rename from lib/ngx/balancer.lua rename to lib/ngx/balancer_http.lua diff --git a/lib/ngx/balancer_stream.lua b/lib/ngx/balancer_stream.lua new file mode 100644 index 000000000..fffa39a04 --- /dev/null +++ b/lib/ngx/balancer_stream.lua @@ -0,0 +1,82 @@ +-- Copyright (C) Yichun Zhang (agentzh) + + +local ffi = require "ffi" +local base = require "resty.core.base" + + +local C = ffi.C +local ffi_str = ffi.string +local errmsg = base.get_errmsg_ptr() +local FFI_OK = base.FFI_OK +local FFI_ERROR = base.FFI_ERROR +local int_out = ffi.new("int[1]") +local getfenv = getfenv +local error = error +local type = type +local tonumber = tonumber + + +ffi.cdef[[ +int ngx_stream_lua_ffi_balancer_set_current_peer(ngx_stream_session_t *r, + const unsigned char *addr, size_t addr_len, int port, char **err); + +int ngx_stream_lua_ffi_balancer_set_more_tries(ngx_stream_session_t *r, + int count, char **err); + +int ngx_stream_lua_ffi_balancer_get_last_failure(ngx_stream_session_t *r, + int *status, char **err); +]] + + +local peer_state_names = { + [1] = "keepalive", + [2] = "next", + [4] = "failed", +} + + +local _M = { version = base.version } + + +function _M.set_current_peer(addr, port) + local r = getfenv(0).__ngx_sess + if not r then + return error("no request found") + end + + if not port then + port = 0 + elseif type(port) ~= "number" then + port = tonumber(port) + end + + local rc = C.ngx_stream_lua_ffi_balancer_set_current_peer(r, addr, #addr, + port, errmsg) + if rc == FFI_OK then + return true + end + + return nil, ffi_str(errmsg[0]) +end + + +function _M.set_more_tries(count) + local r = getfenv(0).__ngx_sess + if not r then + return error("no request found") + end + + local rc = C.ngx_stream_lua_ffi_balancer_set_more_tries(r, count, errmsg) + if rc == FFI_OK then + if errmsg[0] == nil then + return true + end + return true, ffi_str(errmsg[0]) -- return the warning + end + + return nil, ffi_str(errmsg[0]) +end + + +return _M From ce47583ef7a3eb798195f544e91161dcecf81c16 Mon Sep 17 00:00:00 2001 From: splitice Date: Fri, 5 Feb 2016 10:19:34 +1100 Subject: [PATCH 04/11] add missing typedef --- lib/resty/core/base.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/resty/core/base.lua b/lib/resty/core/base.lua index 452708d8e..6de5fa9e3 100644 --- a/lib/resty/core/base.lua +++ b/lib/resty/core/base.lua @@ -81,6 +81,14 @@ if not pcall(ffi.typeof, "ngx_http_request_t") then end +if not pcall(ffi.typeof, "ngx_stream_session_t") then + ffi.cdef[[ + struct ngx_stream_session_s; + typedef struct ngx_stream_session_s ngx_stream_session_t; + ]] +end + + if not pcall(ffi.typeof, "ngx_http_lua_ffi_str_t") then ffi.cdef[[ typedef struct { From b69c14124ad0582d6d5d78e6c6f5014459bd8c41 Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Wed, 10 Aug 2016 22:16:46 -0400 Subject: [PATCH 05/11] fix makefiles, add test suite --- Makefile | 3 +- lib/ngx/balancer/stream.lua | 30 +++- t/balancer-stream.t | 299 ++++++++++++++++++++++++++++++++++++ 3 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 t/balancer-stream.t diff --git a/Makefile b/Makefile index 834b53e64..baefcbf9a 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,11 @@ all: ; install: all $(INSTALL) -d $(DESTDIR)$(LUA_LIB_DIR)/resty/core/ - $(INSTALL) -d $(DESTDIR)$(LUA_LIB_DIR)/ngx/ + $(INSTALL) -d $(DESTDIR)$(LUA_LIB_DIR)/ngx/balancer/ $(INSTALL) lib/resty/*.lua $(DESTDIR)$(LUA_LIB_DIR)/resty/ $(INSTALL) lib/resty/core/*.lua $(DESTDIR)$(LUA_LIB_DIR)/resty/core/ $(INSTALL) lib/ngx/*.lua $(DESTDIR)$(LUA_LIB_DIR)/ngx/ + $(INSTALL) lib/ngx/balancer/*.lua $(DESTDIR)$(LUA_LIB_DIR)/ngx/balancer/ test: all PATH=$(OPENRESTY_PREFIX)/nginx/sbin:$$PATH prove -I../test-nginx/lib -r t diff --git a/lib/ngx/balancer/stream.lua b/lib/ngx/balancer/stream.lua index fffa39a04..e084ea459 100644 --- a/lib/ngx/balancer/stream.lua +++ b/lib/ngx/balancer/stream.lua @@ -42,7 +42,7 @@ local _M = { version = base.version } function _M.set_current_peer(addr, port) local r = getfenv(0).__ngx_sess if not r then - return error("no request found") + return error("no session found") end if not port then @@ -64,7 +64,7 @@ end function _M.set_more_tries(count) local r = getfenv(0).__ngx_sess if not r then - return error("no request found") + return error("no session found") end local rc = C.ngx_stream_lua_ffi_balancer_set_more_tries(r, count, errmsg) @@ -79,4 +79,30 @@ function _M.set_more_tries(count) end +function _M.get_last_failure() + local r = getfenv(0).__ngx_sess + if not r then + return error("no session found") + end + + local state = C.ngx_stream_lua_ffi_balancer_get_last_failure(r, + int_out, + errmsg) + + if state == 0 then + return nil + end + + if state == FFI_ERROR then + return nil, nil, ffi_str(errmsg[0]) + end + + return peer_state_names[state] or "unknown", int_out[0] +end + +function _M.set_timeouts(connect_timeout, send_timeout, read_timeout) + return error("not implemented") +end + + return _M diff --git a/t/balancer-stream.t b/t/balancer-stream.t new file mode 100644 index 000000000..1f03e60df --- /dev/null +++ b/t/balancer-stream.t @@ -0,0 +1,299 @@ +# vim:set ft= ts=4 sw=4 et fdm=marker: + +use Test::Nginx::Socket::Lua::Stream; +use Cwd qw(cwd); + +#worker_connections(1014); +#master_on(); +#workers(2); +#log_level('warn'); + +repeat_each(2); + +plan tests => repeat_each() * (blocks() * 3 + 2); + +$ENV{TEST_NGINX_CWD} = cwd(); + +#worker_connections(1024); +#no_diff(); +no_shuffle(); +no_long_string(); +run_tests(); + +__DATA__ + +=== TEST 1: set current peer (separate addr and port) +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer.stream" + assert(b.set_current_peer("127.0.0.3", 12345)) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +[ +'[lua] balancer_by_lua:2: hello from balancer by lua! while connecting to upstream,', +qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, +] +--- no_error_log +[warn] + + + +=== TEST 2: set current peer & next upstream (3 tries) +--- skip_nginx: 4: < 1.7.5 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + proxy_next_upstream_tries 10; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer.stream" + if not ngx.ctx.tries then + ngx.ctx.tries = 0 + end + + if ngx.ctx.tries < 2 then + local ok, err = b.set_more_tries(1) + if not ok then + return error("failed to set more tries: ", err) + elseif err then + ngx.log(ngx.WARN, "set more tries: ", err) + end + end + ngx.ctx.tries = ngx.ctx.tries + 1 + assert(b.set_current_peer("127.0.0.3", 12345)) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr{connect\(\) to failed .*, upstream: ".*?"} +--- grep_error_log_out eval +qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){3}$# +--- no_error_log +[warn] + + + +=== TEST 3: set current peer & next upstream (no retries) +--- skip_nginx: 4: < 1.7.5 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer.stream" + if not ngx.ctx.tries then + ngx.ctx.tries = 0 + end + + ngx.ctx.tries = ngx.ctx.tries + 1 + assert(b.set_current_peer("127.0.0.3", 12345)) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr{connect\(\) failed .*, upstream: ".*?"} +--- grep_error_log_out eval +qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){1}$# +--- no_error_log +[warn] + + + +=== TEST 4: set current peer & next upstream (3 tries exceeding the limit) +--- skip_nginx: 4: < 1.7.5 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + proxy_next_upstream_tries 2; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + local b = require "ngx.balancer.stream" + + if not ngx.ctx.tries then + ngx.ctx.tries = 0 + end + + if ngx.ctx.tries < 2 then + local ok, err = b.set_more_tries(1) + if not ok then + return error("failed to set more tries: ", err) + elseif err then + ngx.log(ngx.WARN, "set more tries: ", err) + end + end + ngx.ctx.tries = ngx.ctx.tries + 1 + assert(b.set_current_peer("127.0.0.3", 12345)) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr{connect\(\) failed .*, upstream: ".*?"} +--- grep_error_log_out eval +qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){2}$# +--- error_log +set more tries: reduced tries due to limit + + + +=== TEST 5: set current peer (port embedded in addr) +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer.stream" + assert(b.set_current_peer("127.0.0.3:12345")) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +[ +'[lua] balancer_by_lua:2: hello from balancer by lua! while connecting to upstream,', +qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, +] +--- no_error_log +[warn] + + + +=== TEST 6: set_current_peer called in a wrong context +--- wait: 0.2 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 127.0.0.1:$TEST_NGINX_SERVER_PORT; + balancer_by_lua_block { + print("hello from balancer by lua!") + } + } + +--- stream_server_config + proxy_pass backend; + + content_by_lua_block { + local balancer = require "ngx.balancer.stream" + local ok, err = balancer.set_current_peer("127.0.0.1", 1234) + if not ok then + ngx.log(ngx.ERR, "failed to call: ", err) + return + end + ngx.log(ngx.ALERT, "unexpected success") + } +--- error_log eval +qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current context/ +--- no_error_log +[alert] + + + +=== TEST 7: get_last_failure called in a wrong context +--- wait: 0.2 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 127.0.0.1:$TEST_NGINX_SERVER_PORT; + balancer_by_lua_block { + print("hello from balancer by lua!") + } + } + +--- stream_server_config + proxy_pass backend; + + content_by_lua_block { + local balancer = require "ngx.balancer.stream" + local state, status, err = balancer.get_last_failure() + if not state and err then + ngx.log(ngx.ERR, "failed to call: ", err) + return + end + ngx.log(ngx.ALERT, "unexpected success") + } +--- error_log eval +qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current context/ +--- no_error_log +[alert] + + + +=== TEST 8: set_more_tries called in a wrong context +--- wait: 0.2 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 127.0.0.1:$TEST_NGINX_SERVER_PORT; + balancer_by_lua_block { + print("hello from balancer by lua!") + } + } + +--- stream_server_config + proxy_pass backend; + + content_by_lua_block { + local balancer = require "ngx.balancer.stream" + local ok, err = balancer.set_more_tries(1) + if not ok then + ngx.log(ngx.ERR, "failed to call: ", err) + return + end + ngx.log(ngx.ALERT, "unexpected success") + } +--- error_log eval +qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current context/ +--- no_error_log +[alert] + + + +=== TEST 9: test ngx.var.upstream_addr after using more than one set_current_peer +--- wait: 0.2 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + proxy_next_upstream_tries 3; + + upstream backend { + server 127.0.0.1:$TEST_NGINX_SERVER_PORT; + balancer_by_lua_block { + local balancer = require "ngx.balancer.stream" + if ngx.ctx.tries == nil then + balancer.set_more_tries(1) + ngx.ctx.tries = 1 + balancer.set_current_peer("127.0.0.3", 12345) + else + balancer.set_current_peer("127.0.0.3", 12346) + end + } + } + +--- stream_server_config + proxy_pass backend; + content_by_lua_block { + ngx.say("ngx.var.upstream_addr is " .. ngx.var.upstream_addr) + } +--- stream_response +ngx.var.upstream_addr is 127.0.0.3:12346 +--- no_error_log +[alert] From 11bdb357409671f80ac54d15086554e10355ec42 Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Wed, 10 Aug 2016 22:19:28 -0400 Subject: [PATCH 06/11] remove no_shuffle from tests --- t/balancer-stream.t | 1 - 1 file changed, 1 deletion(-) diff --git a/t/balancer-stream.t b/t/balancer-stream.t index 1f03e60df..fabcb975d 100644 --- a/t/balancer-stream.t +++ b/t/balancer-stream.t @@ -16,7 +16,6 @@ $ENV{TEST_NGINX_CWD} = cwd(); #worker_connections(1024); #no_diff(); -no_shuffle(); no_long_string(); run_tests(); From 9bfa3e17796eb19c9ba40f95cfee6a82e3eb926a Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Sun, 14 Aug 2016 09:52:51 -0400 Subject: [PATCH 07/11] update travis - wip --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bbbfbb897..d4cb630a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ install: - git clone https://github.com/openresty/nginx-devel-utils.git - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module + - git clone https://github.com/rshriram/stream-lua-nginx-module.git ../stream-lua-nginx-module - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module - git clone https://github.com/openresty/lua-resty-lrucache.git @@ -68,7 +69,7 @@ script: - export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH - export TEST_NGINX_RESOLVER=8.8.4.4 - export NGX_BUILD_CC=$CC - - ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --with-debug > build.log 2>&1 || (cat build.log && exit 1) + - ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --add-module=../stream-lua-nginx --with-debug > build.log 2>&1 || (cat build.log && exit 1) - nginx -V - ldd `which nginx`|grep -E 'luajit|ssl|pcre' - prove -r t From 9ccc63c5eb995020b49c73a8eec1444990b6033f Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Sun, 14 Aug 2016 11:05:54 -0400 Subject: [PATCH 08/11] timeout tests and travis fixes (#1) * fix typo in build command * timeout tests for streams --- .travis.yml | 2 +- t/balancer-timeout-stream.t | 301 ++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 t/balancer-timeout-stream.t diff --git a/.travis.yml b/.travis.yml index d4cb630a3..d8dc41dc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ script: - export LD_LIBRARY_PATH=$PWD/mockeagain:$LD_LIBRARY_PATH - export TEST_NGINX_RESOLVER=8.8.4.4 - export NGX_BUILD_CC=$CC - - ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --add-module=../stream-lua-nginx --with-debug > build.log 2>&1 || (cat build.log && exit 1) + - ngx-build $NGINX_VERSION --with-ipv6 --with-http_realip_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-cc-opt="-I$OPENSSL_INC" --with-ld-opt="-L$OPENSSL_LIB -Wl,-rpath,$OPENSSL_LIB" --add-module=../ndk-nginx-module --add-module=../echo-nginx-module --add-module=../headers-more-nginx-module --add-module=../lua-nginx-module --add-module=../stream-lua-nginx-module --with-debug > build.log 2>&1 || (cat build.log && exit 1) - nginx -V - ldd `which nginx`|grep -E 'luajit|ssl|pcre' - prove -r t diff --git a/t/balancer-timeout-stream.t b/t/balancer-timeout-stream.t new file mode 100644 index 000000000..e1af50645 --- /dev/null +++ b/t/balancer-timeout-stream.t @@ -0,0 +1,301 @@ +# vim:set ft= ts=4 sw=4 et fdm=marker: + +BEGIN { + if (!defined $ENV{LD_PRELOAD}) { + $ENV{LD_PRELOAD} = ''; + } + + if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) { + $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}"; + } + + if (defined $ENV{MOCKEAGAIN} && $ENV{MOCKEAGAIN} eq 'r') { + $ENV{MOCKEAGAIN} = 'rw'; + + } else { + $ENV{MOCKEAGAIN} = 'w'; + } + + $ENV{TEST_NGINX_EVENT_TYPE} = 'poll'; + $ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1; +} + +use Test::Nginx::Socket::Lua::Stream; +use Cwd qw(cwd); + +#worker_connections(1014); +#master_on(); +#workers(2); +#log_level('warn'); + +repeat_each(2); + +plan tests => repeat_each() * (blocks() * 2 + 4); + +$ENV{TEST_NGINX_CWD} = cwd(); + +#worker_connections(1024); +#no_diff(); +no_long_string(); +run_tests(); + +__DATA__ + +=== TEST 1: set_timeouts +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + local b = require "ngx.balancer" + assert(b.set_timeouts(1.234, 5.678, 7.689)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ +--- grep_error_log_out eval +qr/\Aevent timer add: \d+: 1234: +event timer add: \d+: 5678: +event timer add: \d+: 7689: +\z/ +--- no_error_log +[warn] + + + +=== TEST 2: set_timeouts (nil connect timeout) +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + proxy_connect_timeout 1234ms; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + local b = require "ngx.balancer" + assert(b.set_timeouts(nil, 5.678, 7.689)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ +--- grep_error_log_out eval +qr/\Aevent timer add: \d+: 1234: +event timer add: \d+: 5678: +event timer add: \d+: 7689: +\z/ +--- no_error_log +[warn] + + + +=== TEST 3: set_timeouts (nil send timeout) +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + proxy_send_timeout 5678ms; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + local b = require "ngx.balancer" + assert(b.set_timeouts(1.234, nil, 7.689)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ +--- grep_error_log_out eval +qr/\Aevent timer add: \d+: 1234: +event timer add: \d+: 5678: +event timer add: \d+: 7689: +\z/ +--- no_error_log +[warn] + + + +=== TEST 4: set_timeouts (nil read timeout) +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + proxy_read_timeout 7689ms; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + local b = require "ngx.balancer" + assert(b.set_timeouts(1.234, 5.678, nil)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ +--- grep_error_log_out eval +qr/\Aevent timer add: \d+: 1234: +event timer add: \d+: 5678: +event timer add: \d+: 7689: +\z/ +--- no_error_log +[warn] + + + +=== TEST 5: set connect timeout to 0 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer" + assert(b.set_timeouts(0, 1.234, 5.678)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +qr/\[error\] .*? balancer_by_lua:4: bad connect timeout/ +--- no_error_log +[warn] + + + +=== TEST 6: set connect timeout to -1 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer" + assert(b.set_timeouts(-1, 1.234, 5.678)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +qr/\[error\] .*? balancer_by_lua:4: bad connect timeout/ +--- no_error_log +[warn] + + + +=== TEST 7: set send timeout to 0 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer" + assert(b.set_timeouts(1.234, 0, 5.678)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +qr/\[error\] .*? balancer_by_lua:4: bad send timeout/ +--- no_error_log +[warn] + + + +=== TEST 8: set send timeout to -1 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer" + assert(b.set_timeouts(1.234, -1, 5.678)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +qr/\[error\] .*? balancer_by_lua:4: bad send timeout/ +--- no_error_log +[warn] + + + +=== TEST 9: set read timeout to -1 +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + print("hello from balancer by lua!") + local b = require "ngx.balancer" + assert(b.set_timeouts(1.234, 5.678, -1)) + assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) + } + } +--- stream_server_config + proxy_pass backend; +--- error_log eval +qr/\[error\] .*? balancer_by_lua:4: bad read timeout/ +--- no_error_log +[warn] + + + +=== TEST 10: set_timeouts called in a wrong context +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + +--- stream_server_config + proxy_pass backend; + + content_by_lua_block { + local balancer = require "ngx.balancer" + local ok, err = balancer.set_timeouts(1, 1, 1) + if not ok then + ngx.log(ngx.ERR, "failed to call: ", err) + return + end + ngx.log(ngx.ALERT, "unexpected success!") + } +--- error_log eval +qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current context/ +--- no_error_log +[error] +[alert] + + + +=== TEST 11: set_timeouts called with a non-numerical parameter +--- stream_config + lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; + + upstream backend { + server 0.0.0.1:80; + balancer_by_lua_block { + local balancer = require "ngx.balancer" + local ok, err = balancer.set_timeouts("1.234", 1, 1) + if not ok then + ngx.log(ngx.ERR, "failed to call: ", err) + end + } + } + +--- stream_server_config + proxy_pass backend; +--- error_log eval +qr/\[error\] .*? bad connect timeout/ +--- no_error_log +[alert] From ea3675e36c4191dbd0ae3f7f346516fd294a59f2 Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Tue, 16 Aug 2016 18:13:41 -0400 Subject: [PATCH 09/11] remove stream timeout tests --- t/balancer-timeout-stream.t | 301 ------------------------------------ 1 file changed, 301 deletions(-) delete mode 100644 t/balancer-timeout-stream.t diff --git a/t/balancer-timeout-stream.t b/t/balancer-timeout-stream.t deleted file mode 100644 index e1af50645..000000000 --- a/t/balancer-timeout-stream.t +++ /dev/null @@ -1,301 +0,0 @@ -# vim:set ft= ts=4 sw=4 et fdm=marker: - -BEGIN { - if (!defined $ENV{LD_PRELOAD}) { - $ENV{LD_PRELOAD} = ''; - } - - if ($ENV{LD_PRELOAD} !~ /\bmockeagain\.so\b/) { - $ENV{LD_PRELOAD} = "mockeagain.so $ENV{LD_PRELOAD}"; - } - - if (defined $ENV{MOCKEAGAIN} && $ENV{MOCKEAGAIN} eq 'r') { - $ENV{MOCKEAGAIN} = 'rw'; - - } else { - $ENV{MOCKEAGAIN} = 'w'; - } - - $ENV{TEST_NGINX_EVENT_TYPE} = 'poll'; - $ENV{TEST_NGINX_POSTPONE_OUTPUT} = 1; -} - -use Test::Nginx::Socket::Lua::Stream; -use Cwd qw(cwd); - -#worker_connections(1014); -#master_on(); -#workers(2); -#log_level('warn'); - -repeat_each(2); - -plan tests => repeat_each() * (blocks() * 2 + 4); - -$ENV{TEST_NGINX_CWD} = cwd(); - -#worker_connections(1024); -#no_diff(); -no_long_string(); -run_tests(); - -__DATA__ - -=== TEST 1: set_timeouts ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - local b = require "ngx.balancer" - assert(b.set_timeouts(1.234, 5.678, 7.689)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ ---- grep_error_log_out eval -qr/\Aevent timer add: \d+: 1234: -event timer add: \d+: 5678: -event timer add: \d+: 7689: -\z/ ---- no_error_log -[warn] - - - -=== TEST 2: set_timeouts (nil connect timeout) ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - proxy_connect_timeout 1234ms; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - local b = require "ngx.balancer" - assert(b.set_timeouts(nil, 5.678, 7.689)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ ---- grep_error_log_out eval -qr/\Aevent timer add: \d+: 1234: -event timer add: \d+: 5678: -event timer add: \d+: 7689: -\z/ ---- no_error_log -[warn] - - - -=== TEST 3: set_timeouts (nil send timeout) ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - proxy_send_timeout 5678ms; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - local b = require "ngx.balancer" - assert(b.set_timeouts(1.234, nil, 7.689)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ ---- grep_error_log_out eval -qr/\Aevent timer add: \d+: 1234: -event timer add: \d+: 5678: -event timer add: \d+: 7689: -\z/ ---- no_error_log -[warn] - - - -=== TEST 4: set_timeouts (nil read timeout) ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - proxy_read_timeout 7689ms; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - local b = require "ngx.balancer" - assert(b.set_timeouts(1.234, 5.678, nil)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- grep_error_log eval: qr/event timer add: \d+: (?:1234|5678|7689):/ ---- grep_error_log_out eval -qr/\Aevent timer add: \d+: 1234: -event timer add: \d+: 5678: -event timer add: \d+: 7689: -\z/ ---- no_error_log -[warn] - - - -=== TEST 5: set connect timeout to 0 ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - print("hello from balancer by lua!") - local b = require "ngx.balancer" - assert(b.set_timeouts(0, 1.234, 5.678)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- error_log eval -qr/\[error\] .*? balancer_by_lua:4: bad connect timeout/ ---- no_error_log -[warn] - - - -=== TEST 6: set connect timeout to -1 ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - print("hello from balancer by lua!") - local b = require "ngx.balancer" - assert(b.set_timeouts(-1, 1.234, 5.678)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- error_log eval -qr/\[error\] .*? balancer_by_lua:4: bad connect timeout/ ---- no_error_log -[warn] - - - -=== TEST 7: set send timeout to 0 ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - print("hello from balancer by lua!") - local b = require "ngx.balancer" - assert(b.set_timeouts(1.234, 0, 5.678)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- error_log eval -qr/\[error\] .*? balancer_by_lua:4: bad send timeout/ ---- no_error_log -[warn] - - - -=== TEST 8: set send timeout to -1 ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - print("hello from balancer by lua!") - local b = require "ngx.balancer" - assert(b.set_timeouts(1.234, -1, 5.678)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- error_log eval -qr/\[error\] .*? balancer_by_lua:4: bad send timeout/ ---- no_error_log -[warn] - - - -=== TEST 9: set read timeout to -1 ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - print("hello from balancer by lua!") - local b = require "ngx.balancer" - assert(b.set_timeouts(1.234, 5.678, -1)) - assert(b.set_current_peer("127.0.0.1", tonumber(ngx.var.server_port))) - } - } ---- stream_server_config - proxy_pass backend; ---- error_log eval -qr/\[error\] .*? balancer_by_lua:4: bad read timeout/ ---- no_error_log -[warn] - - - -=== TEST 10: set_timeouts called in a wrong context ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - ---- stream_server_config - proxy_pass backend; - - content_by_lua_block { - local balancer = require "ngx.balancer" - local ok, err = balancer.set_timeouts(1, 1, 1) - if not ok then - ngx.log(ngx.ERR, "failed to call: ", err) - return - end - ngx.log(ngx.ALERT, "unexpected success!") - } ---- error_log eval -qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current context/ ---- no_error_log -[error] -[alert] - - - -=== TEST 11: set_timeouts called with a non-numerical parameter ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - - upstream backend { - server 0.0.0.1:80; - balancer_by_lua_block { - local balancer = require "ngx.balancer" - local ok, err = balancer.set_timeouts("1.234", 1, 1) - if not ok then - ngx.log(ngx.ERR, "failed to call: ", err) - end - } - } - ---- stream_server_config - proxy_pass backend; ---- error_log eval -qr/\[error\] .*? bad connect timeout/ ---- no_error_log -[alert] From e1e3eddc1c918d2040557dc5070d23afa58ca17e Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Sun, 21 Aug 2016 19:49:08 -0400 Subject: [PATCH 10/11] add stream context check in balancer.lua. Fix tests --- lib/ngx/balancer.lua | 4 ++- lib/ngx/balancer/stream.lua | 5 +-- t/balancer-stream.t | 62 ++++++++++--------------------------- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/lib/ngx/balancer.lua b/lib/ngx/balancer.lua index 9582b1d13..4829950d6 100644 --- a/lib/ngx/balancer.lua +++ b/lib/ngx/balancer.lua @@ -1,10 +1,12 @@ -- Copyright (C) Yichun Zhang (agentzh) +if ngx.config.subsystem == "stream" then + return require "ngx.balancer.stream" +end local ffi = require "ffi" local base = require "resty.core.base" - local C = ffi.C local ffi_str = ffi.string local errmsg = base.get_errmsg_ptr() diff --git a/lib/ngx/balancer/stream.lua b/lib/ngx/balancer/stream.lua index e084ea459..ca6223d4e 100644 --- a/lib/ngx/balancer/stream.lua +++ b/lib/ngx/balancer/stream.lua @@ -1,5 +1,6 @@ --- Copyright (C) Yichun Zhang (agentzh) - +-- Copyright (C) Shriram Rajagopalan +-- I hereby assign copyright in this code to the lua-resty-core project, +-- to be licensed under the same terms as the rest of the code. local ffi = require "ffi" local base = require "resty.core.base" diff --git a/t/balancer-stream.t b/t/balancer-stream.t index fabcb975d..f579d1eb1 100644 --- a/t/balancer-stream.t +++ b/t/balancer-stream.t @@ -29,7 +29,7 @@ __DATA__ server 0.0.0.1:80; balancer_by_lua_block { print("hello from balancer by lua!") - local b = require "ngx.balancer.stream" + local b = require "ngx.balancer" assert(b.set_current_peer("127.0.0.3", 12345)) } } @@ -38,7 +38,7 @@ __DATA__ --- error_log eval [ '[lua] balancer_by_lua:2: hello from balancer by lua! while connecting to upstream,', -qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, +qr{connect\(\) failed .*?, upstream: "127.0.0.3:12345"}, ] --- no_error_log [warn] @@ -56,7 +56,7 @@ qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, server 0.0.0.1:80; balancer_by_lua_block { print("hello from balancer by lua!") - local b = require "ngx.balancer.stream" + local b = require "ngx.balancer" if not ngx.ctx.tries then ngx.ctx.tries = 0 end @@ -75,9 +75,9 @@ qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, } --- stream_server_config proxy_pass backend; ---- grep_error_log eval: qr{connect\(\) to failed .*, upstream: ".*?"} +--- grep_error_log eval: qr{connect\(\) failed .*?, upstream: ".*?"} --- grep_error_log_out eval -qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){3}$# +qr#^(?:connect\(\) failed .*?, upstream: "127.0.0.3:12345"\n){3}$# --- no_error_log [warn] @@ -93,7 +93,7 @@ qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){3}$# server 0.0.0.1:80; balancer_by_lua_block { print("hello from balancer by lua!") - local b = require "ngx.balancer.stream" + local b = require "ngx.balancer" if not ngx.ctx.tries then ngx.ctx.tries = 0 end @@ -104,15 +104,16 @@ qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){3}$# } --- stream_server_config proxy_pass backend; ---- grep_error_log eval: qr{connect\(\) failed .*, upstream: ".*?"} +--- grep_error_log eval: qr{connect\(\) failed .*?, upstream: ".*?"} --- grep_error_log_out eval -qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){1}$# +qr#^(?:connect\(\) failed .*?, upstream: "127.0.0.3:12345"\n){1}$# --- no_error_log [warn] === TEST 4: set current peer & next upstream (3 tries exceeding the limit) +--- SKIP unlike HTTP, proxy srv conf struct that contains the retry config is not exposed via public interface --- skip_nginx: 4: < 1.7.5 --- stream_config lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; @@ -122,9 +123,10 @@ qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){1}$# upstream backend { server 0.0.0.1:80; balancer_by_lua_block { - local b = require "ngx.balancer.stream" + local b = require "ngx.balancer" if not ngx.ctx.tries then + print('ngx.ctx.tries is nil') ngx.ctx.tries = 0 end @@ -144,7 +146,7 @@ qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){1}$# proxy_pass backend; --- grep_error_log eval: qr{connect\(\) failed .*, upstream: ".*?"} --- grep_error_log_out eval -qr#^(?:connect\(\) to failed .*?, upstream: "127.0.0.3:12345"\n){2}$# +qr#^(?:connect\(\) failed .*?, upstream: "127.0.0.3:12345"\n){2}$# --- error_log set more tries: reduced tries due to limit @@ -158,7 +160,7 @@ set more tries: reduced tries due to limit server 0.0.0.1:80; balancer_by_lua_block { print("hello from balancer by lua!") - local b = require "ngx.balancer.stream" + local b = require "ngx.balancer" assert(b.set_current_peer("127.0.0.3:12345")) } } @@ -167,7 +169,7 @@ set more tries: reduced tries due to limit --- error_log eval [ '[lua] balancer_by_lua:2: hello from balancer by lua! while connecting to upstream,', -qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, +qr{connect\(\) failed .*?, upstream: "127.0.0.3:12345"}, ] --- no_error_log [warn] @@ -190,7 +192,7 @@ qr{connect\(\) to failed .*?, upstream: "127\.0\.0\.3:12345"}, proxy_pass backend; content_by_lua_block { - local balancer = require "ngx.balancer.stream" + local balancer = require "ngx.balancer" local ok, err = balancer.set_current_peer("127.0.0.1", 1234) if not ok then ngx.log(ngx.ERR, "failed to call: ", err) @@ -221,7 +223,7 @@ qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current c proxy_pass backend; content_by_lua_block { - local balancer = require "ngx.balancer.stream" + local balancer = require "ngx.balancer" local state, status, err = balancer.get_last_failure() if not state and err then ngx.log(ngx.ERR, "failed to call: ", err) @@ -252,7 +254,7 @@ qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current c proxy_pass backend; content_by_lua_block { - local balancer = require "ngx.balancer.stream" + local balancer = require "ngx.balancer" local ok, err = balancer.set_more_tries(1) if not ok then ngx.log(ngx.ERR, "failed to call: ", err) @@ -266,33 +268,3 @@ qr/\[error\] .*? content_by_lua.*? failed to call: API disabled in the current c [alert] - -=== TEST 9: test ngx.var.upstream_addr after using more than one set_current_peer ---- wait: 0.2 ---- stream_config - lua_package_path "$TEST_NGINX_CWD/lib/?.lua;;"; - proxy_next_upstream_tries 3; - - upstream backend { - server 127.0.0.1:$TEST_NGINX_SERVER_PORT; - balancer_by_lua_block { - local balancer = require "ngx.balancer.stream" - if ngx.ctx.tries == nil then - balancer.set_more_tries(1) - ngx.ctx.tries = 1 - balancer.set_current_peer("127.0.0.3", 12345) - else - balancer.set_current_peer("127.0.0.3", 12346) - end - } - } - ---- stream_server_config - proxy_pass backend; - content_by_lua_block { - ngx.say("ngx.var.upstream_addr is " .. ngx.var.upstream_addr) - } ---- stream_response -ngx.var.upstream_addr is 127.0.0.3:12346 ---- no_error_log -[alert] From 9e5cd72af3cb9839b37001d263829bc23eef3ccf Mon Sep 17 00:00:00 2001 From: Shriram Rajagopalan Date: Sun, 21 Aug 2016 19:49:29 -0400 Subject: [PATCH 11/11] pointing travis back to openresty repo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d8dc41dc2..260ef3f36 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ install: - git clone https://github.com/openresty/nginx-devel-utils.git - git clone https://github.com/simpl/ngx_devel_kit.git ../ndk-nginx-module - git clone https://github.com/openresty/lua-nginx-module.git ../lua-nginx-module - - git clone https://github.com/rshriram/stream-lua-nginx-module.git ../stream-lua-nginx-module + - git clone https://github.com/openresty/stream-lua-nginx-module.git ../stream-lua-nginx-module - git clone https://github.com/openresty/no-pool-nginx.git ../no-pool-nginx - git clone https://github.com/openresty/echo-nginx-module.git ../echo-nginx-module - git clone https://github.com/openresty/lua-resty-lrucache.git