|
3 | 3 | use lib 'lib';
|
4 | 4 | use Test::Nginx::Socket;
|
5 | 5 |
|
6 |
| -repeat_each(2); |
| 6 | +#repeat_each(2); |
7 | 7 |
|
8 |
| -plan tests => repeat_each() * (blocks() * 5 + 8); |
| 8 | +plan tests => repeat_each() * (blocks() * 5 + 14); |
9 | 9 |
|
10 | 10 | our $HtmlDir = html_dir;
|
11 | 11 |
|
@@ -80,11 +80,11 @@ function go(port)
|
80 | 80 | end
|
81 | 81 | --- request
|
82 | 82 | GET /t
|
83 |
| ---- response_body_like |
84 |
| -^connected: 1, reused: \d+ |
| 83 | +--- response_body |
| 84 | +connected: 1, reused: 0 |
85 | 85 | request sent: 11
|
86 | 86 | received: OK
|
87 |
| -connected: 1, reused: [1-9]\d* |
| 87 | +connected: 1, reused: 1 |
88 | 88 | request sent: 11
|
89 | 89 | received: OK
|
90 | 90 | --- no_error_log eval
|
@@ -153,11 +153,11 @@ function go(port, keepalive)
|
153 | 153 | sock:close()
|
154 | 154 | end
|
155 | 155 | end
|
156 |
| ---- response_body_like |
157 |
| -^connected: 1, reused: \d+ |
| 156 | +--- response_body |
| 157 | +connected: 1, reused: 0 |
158 | 158 | request sent: 11
|
159 | 159 | received: OK
|
160 |
| -connected: 1, reused: [1-9]\d* |
| 160 | +connected: 1, reused: 1 |
161 | 161 | request sent: 11
|
162 | 162 | received: OK
|
163 | 163 | --- no_error_log
|
@@ -844,11 +844,11 @@ function go(path, port)
|
844 | 844 | ngx.say("failed to set reusable: ", err)
|
845 | 845 | end
|
846 | 846 | end
|
847 |
| ---- response_body_like |
848 |
| -^connected: 1, reused: \d+ |
| 847 | +--- response_body |
| 848 | +connected: 1, reused: 0 |
849 | 849 | request sent: 61
|
850 | 850 | received response of 119 bytes
|
851 |
| -connected: 1, reused: [1-9]\d* |
| 851 | +connected: 1, reused: 1 |
852 | 852 | request sent: 61
|
853 | 853 | received response of 119 bytes
|
854 | 854 | --- no_error_log eval
|
@@ -964,3 +964,216 @@ Not found, dear...
|
964 | 964 | --- no_error_log
|
965 | 965 | [error]
|
966 | 966 |
|
| 967 | + |
| 968 | + |
| 969 | +=== TEST 14: custom pools (different pool for the same host:port) - tcp |
| 970 | +--- http_config eval |
| 971 | + "lua_package_path '$::HtmlDir/?.lua;./?.lua';" |
| 972 | +--- config |
| 973 | + location /t { |
| 974 | + set $port $TEST_NGINX_MEMCACHED_PORT; |
| 975 | + content_by_lua ' |
| 976 | + local test = require "test" |
| 977 | + local port = ngx.var.port |
| 978 | + test.go(port, "A") |
| 979 | + test.go(port, "B") |
| 980 | + '; |
| 981 | + } |
| 982 | +--- user_files |
| 983 | +>>> test.lua |
| 984 | +module("test", package.seeall) |
| 985 | + |
| 986 | +function go(port, pool) |
| 987 | + local sock = ngx.socket.tcp() |
| 988 | + local ok, err = sock:connect("127.0.0.1", port, {pool = pool}) |
| 989 | + if not ok then |
| 990 | + ngx.say("failed to connect: ", err) |
| 991 | + return |
| 992 | + end |
| 993 | + |
| 994 | + ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes()) |
| 995 | + |
| 996 | + local ok, err = sock:setkeepalive() |
| 997 | + if not ok then |
| 998 | + ngx.say("failed to set reusable: ", err) |
| 999 | + end |
| 1000 | +end |
| 1001 | +--- request |
| 1002 | +GET /t |
| 1003 | +--- response_body |
| 1004 | +connected: 1, reused: 0 |
| 1005 | +connected: 1, reused: 0 |
| 1006 | +--- no_error_log eval |
| 1007 | +["[error]", |
| 1008 | +"lua tcp socket keepalive: free connection pool for ", |
| 1009 | +"lua tcp socket get keepalive peer: using connection" |
| 1010 | +] |
| 1011 | +--- error_log |
| 1012 | +lua tcp socket keepalive create connection pool for key "A" |
| 1013 | +lua tcp socket keepalive create connection pool for key "B" |
| 1014 | + |
| 1015 | + |
| 1016 | + |
| 1017 | +=== TEST 15: custom pools (same pool for different host:port) - tcp |
| 1018 | +--- http_config eval |
| 1019 | + "lua_package_path '$::HtmlDir/?.lua;./?.lua';" |
| 1020 | +--- config |
| 1021 | + location /t { |
| 1022 | + set $port $TEST_NGINX_MEMCACHED_PORT; |
| 1023 | + content_by_lua ' |
| 1024 | + local test = require "test" |
| 1025 | + local port = ngx.var.port |
| 1026 | + test.go($TEST_NGINX_MEMCACHED_PORT, "foo") |
| 1027 | + test.go($TEST_NGINX_CLIENT_PORT, "foo") |
| 1028 | + '; |
| 1029 | + } |
| 1030 | +--- user_files |
| 1031 | +>>> test.lua |
| 1032 | +module("test", package.seeall) |
| 1033 | + |
| 1034 | +function go(port, pool) |
| 1035 | + local sock = ngx.socket.tcp() |
| 1036 | + local ok, err = sock:connect("127.0.0.1", port, {pool = pool}) |
| 1037 | + if not ok then |
| 1038 | + ngx.say("failed to connect: ", err) |
| 1039 | + return |
| 1040 | + end |
| 1041 | + |
| 1042 | + ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes()) |
| 1043 | + |
| 1044 | + local ok, err = sock:setkeepalive() |
| 1045 | + if not ok then |
| 1046 | + ngx.say("failed to set reusable: ", err) |
| 1047 | + end |
| 1048 | +end |
| 1049 | +--- request |
| 1050 | +GET /t |
| 1051 | +--- response_body |
| 1052 | +connected: 1, reused: 0 |
| 1053 | +connected: 1, reused: 1 |
| 1054 | +--- no_error_log eval |
| 1055 | +["[error]", |
| 1056 | +"lua tcp socket keepalive: free connection pool for ", |
| 1057 | +] |
| 1058 | +--- error_log |
| 1059 | +lua tcp socket keepalive create connection pool for key "foo" |
| 1060 | +lua tcp socket get keepalive peer: using connection |
| 1061 | + |
| 1062 | + |
| 1063 | + |
| 1064 | +=== TEST 16: custom pools (different pool for the same host:port) - unix |
| 1065 | +--- http_config eval |
| 1066 | +" |
| 1067 | + lua_package_path '$::HtmlDir/?.lua;./?.lua'; |
| 1068 | + server { |
| 1069 | + listen unix:$::HtmlDir/nginx.sock; |
| 1070 | + default_type 'text/plain'; |
| 1071 | +
|
| 1072 | + server_tokens off; |
| 1073 | + location /foo { |
| 1074 | + echo foo; |
| 1075 | + more_clear_headers Date; |
| 1076 | + } |
| 1077 | + } |
| 1078 | +" |
| 1079 | +--- config |
| 1080 | + location /t { |
| 1081 | + set $port $TEST_NGINX_MEMCACHED_PORT; |
| 1082 | + content_by_lua ' |
| 1083 | + local test = require "test" |
| 1084 | + local path = "$TEST_NGINX_HTML_DIR/nginx.sock"; |
| 1085 | + test.go(path, "A") |
| 1086 | + test.go(path, "B") |
| 1087 | + '; |
| 1088 | + } |
| 1089 | +--- user_files |
| 1090 | +>>> test.lua |
| 1091 | +module("test", package.seeall) |
| 1092 | + |
| 1093 | +function go(path, pool) |
| 1094 | + local sock = ngx.socket.tcp() |
| 1095 | + local ok, err = sock:connect("unix:" .. path, {pool = pool}) |
| 1096 | + if not ok then |
| 1097 | + ngx.say("failed to connect: ", err) |
| 1098 | + return |
| 1099 | + end |
| 1100 | + |
| 1101 | + ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes()) |
| 1102 | + |
| 1103 | + local ok, err = sock:setkeepalive() |
| 1104 | + if not ok then |
| 1105 | + ngx.say("failed to set reusable: ", err) |
| 1106 | + end |
| 1107 | +end |
| 1108 | +--- request |
| 1109 | +GET /t |
| 1110 | +--- response_body |
| 1111 | +connected: 1, reused: 0 |
| 1112 | +connected: 1, reused: 0 |
| 1113 | +--- no_error_log eval |
| 1114 | +["[error]", |
| 1115 | +"lua tcp socket keepalive: free connection pool for ", |
| 1116 | +"lua tcp socket get keepalive peer: using connection" |
| 1117 | +] |
| 1118 | +--- error_log |
| 1119 | +lua tcp socket keepalive create connection pool for key "A" |
| 1120 | +lua tcp socket keepalive create connection pool for key "B" |
| 1121 | + |
| 1122 | + |
| 1123 | +=== TEST 16: custom pools (same pool for the same host:port) - unix |
| 1124 | +--- http_config eval |
| 1125 | +" |
| 1126 | + lua_package_path '$::HtmlDir/?.lua;./?.lua'; |
| 1127 | + server { |
| 1128 | + listen unix:$::HtmlDir/nginx.sock; |
| 1129 | + default_type 'text/plain'; |
| 1130 | +
|
| 1131 | + server_tokens off; |
| 1132 | + location /foo { |
| 1133 | + echo foo; |
| 1134 | + more_clear_headers Date; |
| 1135 | + } |
| 1136 | + } |
| 1137 | +" |
| 1138 | +--- config |
| 1139 | + location /t { |
| 1140 | + set $port $TEST_NGINX_MEMCACHED_PORT; |
| 1141 | + content_by_lua ' |
| 1142 | + local test = require "test" |
| 1143 | + local path = "$TEST_NGINX_HTML_DIR/nginx.sock"; |
| 1144 | + test.go(path, "A") |
| 1145 | + test.go(path, "A") |
| 1146 | + '; |
| 1147 | + } |
| 1148 | +--- user_files |
| 1149 | +>>> test.lua |
| 1150 | +module("test", package.seeall) |
| 1151 | + |
| 1152 | +function go(path, pool) |
| 1153 | + local sock = ngx.socket.tcp() |
| 1154 | + local ok, err = sock:connect("unix:" .. path, {pool = pool}) |
| 1155 | + if not ok then |
| 1156 | + ngx.say("failed to connect: ", err) |
| 1157 | + return |
| 1158 | + end |
| 1159 | + |
| 1160 | + ngx.say("connected: ", ok, ", reused: ", sock:getreusedtimes()) |
| 1161 | + |
| 1162 | + local ok, err = sock:setkeepalive() |
| 1163 | + if not ok then |
| 1164 | + ngx.say("failed to set reusable: ", err) |
| 1165 | + end |
| 1166 | +end |
| 1167 | +--- request |
| 1168 | +GET /t |
| 1169 | +--- response_body |
| 1170 | +connected: 1, reused: 0 |
| 1171 | +connected: 1, reused: 1 |
| 1172 | +--- no_error_log eval |
| 1173 | +["[error]", |
| 1174 | +"lua tcp socket keepalive: free connection pool for ", |
| 1175 | +] |
| 1176 | +--- error_log |
| 1177 | +lua tcp socket keepalive create connection pool for key "A" |
| 1178 | +lua tcp socket get keepalive peer: using connection |
| 1179 | + |
0 commit comments