-
Notifications
You must be signed in to change notification settings - Fork 193
/
014-bugs.t
158 lines (122 loc) · 3.03 KB
/
014-bugs.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# vim:set ft= ts=4 sw=4 et fdm=marker:
use Test::Nginx::Socket::Lua::Stream;
#worker_connections(1014);
#master_on();
log_level('debug');
repeat_each(3);
plan tests => repeat_each() * (blocks() * 3);
our $HtmlDir = html_dir;
#warn $html_dir;
$ENV{TEST_NGINX_HTML_DIR} = $HtmlDir;
$ENV{TEST_NGINX_REDIS_PORT} ||= 6379;
#no_diff();
#no_long_string();
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
$ENV{TEST_NGINX_RESOLVER} ||= '8.8.8.8';
#no_shuffle();
no_long_string();
sub read_file {
my $infile = shift;
open my $in, $infile
or die "cannot open $infile for reading: $!";
my $cert = do { local $/; <$in> };
close $in;
$cert;
}
our $TestCertificate = read_file("t/cert/test.crt");
our $TestCertificateKey = read_file("t/cert/test.key");
run_tests();
__DATA__
=== TEST 1: sanity
--- stream_config eval
"lua_package_path '$::HtmlDir/?.lua;./?.lua';"
--- stream_server_config
content_by_lua_block {
package.loaded.foo = nil;
local foo = require "foo";
foo.hi()
}
--- user_files
>>> foo.lua
module(..., package.seeall);
function foo ()
return 1
return 2
end
--- stream_response
--- error_log
error loading module 'foo' from file
=== TEST 2: print lua empty strings
--- stream_server_config
content_by_lua_block { ngx.print("") ngx.flush() ngx.print("Hi") }
--- stream_response chop
Hi
--- no_error_log
[error]
=== TEST 3: say lua empty strings
--- stream_server_config
content_by_lua_block { ngx.say("") ngx.flush() ngx.print("Hi") }
--- stream_response eval
"
Hi"
--- no_error_log
[error]
=== TEST 4: lua_code_cache off + setkeepalive
--- stream_config eval
"lua_package_path '$::HtmlDir/?.lua;./?.lua';"
--- stream_server_config
lua_code_cache off;
content_by_lua_block {
local test = require "test"
local port = $TEST_NGINX_REDIS_PORT
test.go(port)
}
--- user_files
>>> test.lua
module("test", package.seeall)
function go(port)
local sock = ngx.socket.tcp()
local sock2 = ngx.socket.tcp()
sock:settimeout(1000)
sock2:settimeout(6000000)
local ok, err = sock:connect("127.0.0.1", port)
if not ok then
ngx.say("failed to connect: ", err)
return
end
local ok, err = sock2:connect("127.0.0.1", port)
if not ok then
ngx.say("failed to connect: ", err)
return
end
local ok, err = sock:setkeepalive(100, 100)
if not ok then
ngx.say("failed to set reusable: ", err)
end
local ok, err = sock2:setkeepalive(200, 100)
if not ok then
ngx.say("failed to set reusable: ", err)
end
ngx.say("done")
end
--- stap2
F(ngx_close_connection) {
println("=== close connection")
print_ubacktrace()
}
--- stap_out2
--- stream_response
done
--- wait: 0.5
--- no_error_log
[error]
=== TEST 5: .lua file of exactly N*1024 bytes (github issue #385)
--- stream_server_config
content_by_lua_file html/a.lua;
--- user_files eval
my $s = "ngx.say('ok')\n";
">>> a.lua\n" . (" " x (8192 - length($s))) . $s;
--- stream_response
ok
--- no_error_log
[error]