@@ -4,14 +4,15 @@ use Test::Nginx::Socket::Lua::Stream;
4
4
5
5
repeat_each(2 );
6
6
7
- plan tests => repeat_each() * 132 ;
7
+ plan tests => repeat_each() * 140 ;
8
8
9
9
# $ENV{LUA_PATH} = $ENV{HOME} . '/work/JSON4Lua-0.9.30/json/?.lua';
10
10
11
11
no_long_string();
12
12
13
13
our $ HtmlDir = html_dir;
14
14
15
+ $ ENV {TEST_NGINX_HTML_DIR} = $ HtmlDir ;
15
16
$ ENV {TEST_NGINX_MEMCACHED_PORT} ||= 11211 ;
16
17
17
18
check_accum_error_log();
@@ -959,3 +960,160 @@ qr/\[alert\] \S+ stream lua_code_cache is off; this will hurt performance/,
959
960
"stream lua decrementing the reference count for Lua VM: 1" ,
960
961
"stream lua close the global Lua VM" ,
961
962
]
963
+
964
+
965
+
966
+ === TEST 25 : make sure inline code keys are correct
967
+ -- - stream_config
968
+ include .. / html/ a/ proxy. conf;
969
+ include .. / html/ b/ proxy. conf;
970
+ include .. / html/ c/ proxy. conf;
971
+ -- - stream_server_config
972
+ content_by_lua_block {
973
+ for _, n in ipairs({ 1 , 2 , 1 , 3 }) do
974
+ local sock = ngx. socket. tcp()
975
+ sock: settimeouts(1000 , 1000 , 1000 )
976
+
977
+ local ok , err = sock: connect(" unix:$ TEST_NGINX_HTML_DIR /nginx" .. n .. " .sock" )
978
+ if not ok then
979
+ ngx. log (ngx. ERR, " could not connect: " , err)
980
+ return
981
+ end
982
+
983
+ local res, err = sock: receive(11 )
984
+ if not res then
985
+ ngx. log (ngx. ERR, " could not receive: " , err)
986
+ return
987
+ end
988
+
989
+ ngx. say (res)
990
+
991
+ sock: close()
992
+ end
993
+ }
994
+ -- - user_files
995
+ >>> a/ proxy. conf
996
+ server {
997
+ listen unix: $ TEST_NGINX_HTML_DIR / nginx1. sock;
998
+ content_by_lua_block { ngx. say (" 1 is called" ) }
999
+ }
1000
+
1001
+ >>> b/ proxy. conf
1002
+ server {
1003
+ listen unix: $ TEST_NGINX_HTML_DIR / nginx2. sock;
1004
+ content_by_lua_block { ngx. say (" 2 is called" ) }
1005
+ }
1006
+
1007
+ >>> c/ proxy. conf
1008
+ server {
1009
+ listen unix: $ TEST_NGINX_HTML_DIR / nginx3. sock;
1010
+ content_by_lua_block { ngx. say (" 2 is called" ) }
1011
+ }
1012
+ -- - stream_response
1013
+ 1 is called
1014
+ 2 is called
1015
+ 1 is called
1016
+ 2 is called
1017
+ -- - grep_error_log eval: qr/ looking up Lua code cache with key ' =content_by_lua\(proxy\.conf:\d+\).*?' /
1018
+ -- - grep_error_log_out eval
1019
+ [
1020
+ " looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_ad58d60a0f20ae31b1a282e74053d356'
1021
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_9c867c93f28b91041fe132817b43ad07'
1022
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_ad58d60a0f20ae31b1a282e74053d356'
1023
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_9c867c93f28b91041fe132817b43ad07'
1024
+ " ,
1025
+ " looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_ad58d60a0f20ae31b1a282e74053d356'
1026
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_9c867c93f28b91041fe132817b43ad07'
1027
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_ad58d60a0f20ae31b1a282e74053d356'
1028
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_9c867c93f28b91041fe132817b43ad07'
1029
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_ad58d60a0f20ae31b1a282e74053d356'
1030
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_9c867c93f28b91041fe132817b43ad07'
1031
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_ad58d60a0f20ae31b1a282e74053d356'
1032
+ looking up Lua code cache with key '=content_by_lua(proxy.conf:3)nhli_9c867c93f28b91041fe132817b43ad07'
1033
+ " ]
1034
+ -- - log_level: debug
1035
+ -- - no_error_log
1036
+ [error]
1037
+
1038
+
1039
+
1040
+ === TEST 26 : make sure inline code keys are correct
1041
+ -- - stream_config
1042
+ include .. / html/ a/ proxy. conf;
1043
+ include .. / html/ b/ proxy. conf;
1044
+ include .. / html/ c/ proxy. conf;
1045
+ -- - stream_server_config
1046
+ content_by_lua_block {
1047
+ for _, n in ipairs({ 1 , 2 , 1 , 3 }) do
1048
+ local sock = ngx. socket. tcp()
1049
+ sock: settimeouts(1000 , 1000 , 1000 )
1050
+
1051
+ local ok , err = sock: connect(" unix:$ TEST_NGINX_HTML_DIR /nginx" .. n .. " .sock" )
1052
+ if not ok then
1053
+ ngx. log (ngx. ERR, " could not connect: " , err)
1054
+ return
1055
+ end
1056
+
1057
+ local res, err = sock: receive(11 )
1058
+ if not res then
1059
+ ngx. log (ngx. ERR, " could not receive: " , err)
1060
+ return
1061
+ end
1062
+
1063
+ ngx. say (res)
1064
+
1065
+ sock: close()
1066
+ end
1067
+ }
1068
+ -- - user_files
1069
+ >>> a. lua
1070
+ ngx. say (" 1 is called" )
1071
+
1072
+ >>> b. lua
1073
+ ngx. say (" 2 is called" )
1074
+
1075
+ >>> c. lua
1076
+ ngx. say (" 2 is called" )
1077
+
1078
+ >>> a/ proxy. conf
1079
+ server {
1080
+ listen unix: $ TEST_NGINX_HTML_DIR / nginx1. sock;
1081
+ content_by_lua_file html/ a. lua;
1082
+ }
1083
+
1084
+ >>> b/ proxy. conf
1085
+ server {
1086
+ listen unix: $ TEST_NGINX_HTML_DIR / nginx2. sock;
1087
+ content_by_lua_file html/ b. lua;
1088
+ }
1089
+
1090
+ >>> c/ proxy. conf
1091
+ server {
1092
+ listen unix: $ TEST_NGINX_HTML_DIR / nginx3. sock;
1093
+ content_by_lua_file html/ c. lua;
1094
+ }
1095
+ -- - stream_response
1096
+ 1 is called
1097
+ 2 is called
1098
+ 1 is called
1099
+ 2 is called
1100
+ -- - grep_error_log eval: qr/ looking up Lua code cache with key ' nhlf_.*?' /
1101
+ -- - grep_error_log_out eval
1102
+ [
1103
+ " looking up Lua code cache with key 'nhlf_48a9a7def61143c003a7de1644e026e4'
1104
+ looking up Lua code cache with key 'nhlf_68f5f4e946c3efd1cc206452b807e8b6'
1105
+ looking up Lua code cache with key 'nhlf_48a9a7def61143c003a7de1644e026e4'
1106
+ looking up Lua code cache with key 'nhlf_042c9b3a136fbacbbd0e4b9ad10896b7'
1107
+ " ,
1108
+ " looking up Lua code cache with key 'nhlf_48a9a7def61143c003a7de1644e026e4'
1109
+ looking up Lua code cache with key 'nhlf_68f5f4e946c3efd1cc206452b807e8b6'
1110
+ looking up Lua code cache with key 'nhlf_48a9a7def61143c003a7de1644e026e4'
1111
+ looking up Lua code cache with key 'nhlf_042c9b3a136fbacbbd0e4b9ad10896b7'
1112
+ looking up Lua code cache with key 'nhlf_48a9a7def61143c003a7de1644e026e4'
1113
+ looking up Lua code cache with key 'nhlf_68f5f4e946c3efd1cc206452b807e8b6'
1114
+ looking up Lua code cache with key 'nhlf_48a9a7def61143c003a7de1644e026e4'
1115
+ looking up Lua code cache with key 'nhlf_042c9b3a136fbacbbd0e4b9ad10896b7'
1116
+ " ]
1117
+ -- - log_level: debug
1118
+ -- - no_error_log
1119
+ [error]
0 commit comments