Skip to content

Commit

Permalink
tests: use random ports instead of constant ports to prevent conflict…
Browse files Browse the repository at this point in the history
…s during testing. (#2274)
  • Loading branch information
Johnny Wang authored Dec 25, 2023
1 parent bf5d9d3 commit 766b7a8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 53 deletions.
4 changes: 2 additions & 2 deletions t/014-bugs.t
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ GET /t
--- http_config eval
"lua_package_path '$::HtmlDir/?.lua;./?.lua;;';
server {
listen 12354;
listen \$TEST_NGINX_RAND_PORT_1;

location = /t {
echo 'args: \$args';
Expand All @@ -903,7 +903,7 @@ GET /t
--- config
location = /t {
set $args "foo=1&bar=2";
proxy_pass http://127.0.0.1:12354;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_1;
}

--- request
Expand Down
56 changes: 28 additions & 28 deletions t/020-subrequest.t
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ qr{(\Qcurl: (52) Empty reply from server\E|\Qcurl: (95) HTTP/3 stream 0 reset by

set $memc_key 'foo';
#set $memc_exptime 300;
memc_pass 127.0.0.1:19112; #$TEST_NGINX_MEMCACHED_PORT;
memc_pass 127.0.0.1:$TEST_NGINX_RAND_PORT_1; #$TEST_NGINX_MEMCACHED_PORT;
}

location /main {
Expand All @@ -1253,7 +1253,7 @@ qr{(\Qcurl: (52) Empty reply from server\E|\Qcurl: (95) HTTP/3 stream 0 reset by
}
--- request
GET /main
--- tcp_listen: 19112
--- tcp_listen: $TEST_NGINX_RAND_PORT_1
--- tcp_query_len: 9
--- tcp_reply eval
"VALUE foo 0 1024\r\nhello world"
Expand Down Expand Up @@ -1310,7 +1310,7 @@ upstream prematurely closed connection

set $memc_key 'foo';
#set $memc_exptime 300;
memc_pass 127.0.0.1:19112; #$TEST_NGINX_MEMCACHED_PORT;
memc_pass 127.0.0.1:$TEST_NGINX_RAND_PORT_1; #$TEST_NGINX_MEMCACHED_PORT;
}

location /main {
Expand All @@ -1323,7 +1323,7 @@ upstream prematurely closed connection
}
--- request
GET /main
--- tcp_listen: 19112
--- tcp_listen: $TEST_NGINX_RAND_PORT_1
--- tcp_no_close
--- tcp_reply eval
"VALUE foo 0 1024\r\nhello world"
Expand Down Expand Up @@ -1383,7 +1383,7 @@ upstream timed out

#proxy_read_timeout 100ms;
proxy_buffering on;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1396,7 +1396,7 @@ upstream timed out
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_query_len: 65
--- tcp_reply eval
"HTTP/1.0 200 OK\r\nContent-Length: 1024\r\n\r\nhello world"
Expand Down Expand Up @@ -1443,7 +1443,7 @@ upstream prematurely closed connection

proxy_read_timeout 100ms;
proxy_buffering on;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1456,7 +1456,7 @@ upstream prematurely closed connection
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_no_close
--- tcp_reply eval
"HTTP/1.0 200 OK\r\nContent-Length: 1024\r\n\r\nhello world"
Expand Down Expand Up @@ -1505,7 +1505,7 @@ upstream timed out

#proxy_read_timeout 100ms;
proxy_buffering on;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1518,7 +1518,7 @@ upstream timed out
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_query_len: 65
--- tcp_reply eval
"HTTP/1.0 200 OK\r\n\r\nhello world"
Expand Down Expand Up @@ -1565,7 +1565,7 @@ truncated: false

proxy_read_timeout 100ms;
proxy_buffering on;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1578,7 +1578,7 @@ truncated: false
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_no_close
--- tcp_reply eval
"HTTP/1.0 200 OK\r\n\r\nhello world"
Expand Down Expand Up @@ -1628,7 +1628,7 @@ upstream timed out

#proxy_read_timeout 100ms;
proxy_buffering off;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1641,7 +1641,7 @@ upstream timed out
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_query_len: 65
--- tcp_reply eval
"HTTP/1.0 200 OK\r\n\r\nhello world"
Expand Down Expand Up @@ -1688,7 +1688,7 @@ truncated: false

proxy_read_timeout 500ms;
proxy_buffering off;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1701,7 +1701,7 @@ truncated: false
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_no_close
--- tcp_reply eval
"HTTP/1.0 200 OK\r\n\r\nhello world"
Expand Down Expand Up @@ -1914,7 +1914,7 @@ a client request body is buffered to a temporary file
#proxy_read_timeout 100ms;
proxy_http_version 1.1;
proxy_buffering on;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1927,7 +1927,7 @@ a client request body is buffered to a temporary file
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_query_len: 65
--- tcp_reply eval
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nhello world\r"
Expand Down Expand Up @@ -1977,7 +1977,7 @@ upstream prematurely closed connection
#proxy_read_timeout 100ms;
proxy_http_version 1.1;
proxy_buffering off;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -1990,7 +1990,7 @@ upstream prematurely closed connection
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_query_len: 65
--- tcp_reply eval
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nhello world\r"
Expand Down Expand Up @@ -2038,7 +2038,7 @@ upstream prematurely closed connection
proxy_read_timeout 100ms;
proxy_buffering on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -2051,7 +2051,7 @@ upstream prematurely closed connection
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_no_close
--- tcp_reply eval
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\nb\r\nhello world\r"
Expand Down Expand Up @@ -2100,7 +2100,7 @@ upstream timed out
#proxy_read_timeout 100ms;
proxy_buffering on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -2113,7 +2113,7 @@ upstream timed out
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_no_close
--- tcp_reply eval
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n0\r\n\r\n"
Expand Down Expand Up @@ -2158,7 +2158,7 @@ truncated: false
#proxy_read_timeout 100ms;
proxy_buffering off;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -2171,7 +2171,7 @@ truncated: false
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_no_close
--- tcp_reply eval
"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n0\r\n\r\n"
Expand Down Expand Up @@ -2217,7 +2217,7 @@ truncated: false

#proxy_read_timeout 100ms;
proxy_buffering off;
proxy_pass http://127.0.0.1:19113;
proxy_pass http://127.0.0.1:$TEST_NGINX_RAND_PORT_2;
}

location /main {
Expand All @@ -2230,7 +2230,7 @@ truncated: false
}
--- request
GET /main
--- tcp_listen: 19113
--- tcp_listen: $TEST_NGINX_RAND_PORT_2
--- tcp_query_len: 65
--- tcp_reply eval
"HTTP/1.0 200 OK\r\nContent-Length: 1024\r\n\r\nhello world"
Expand Down
12 changes: 6 additions & 6 deletions t/045-ngx-var.t
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,19 @@ variable "query_string" not changeable
}
server {
# this is the real entry point
listen 8091;
listen $TEST_NGINX_RAND_PORT_1;
location / {
content_by_lua_block{
ngx.print("this is backend peer 8091")
ngx.print("this is backend peer $TEST_NGINX_RAND_PORT_1")
}
}
}
server {
# this is the real entry point
listen 8092;
listen $TEST_NGINX_RAND_PORT_2;
location / {
content_by_lua_block{
ngx.print("this is backend peer 8092")
ngx.print("this is backend peer $TEST_NGINX_RAND_PORT_2")
}
}
}
Expand All @@ -287,6 +287,6 @@ variable "query_string" not changeable
proxy_pass http://balancer;
}
--- pipelined_requests eval
["GET /balancer?port=8091", "GET /balancer?port=8092"]
["GET /balancer?port=\$TEST_NGINX_RAND_PORT_1", "GET /balancer?port=\$TEST_NGINX_RAND_PORT_2"]
--- response_body eval
["this is backend peer 8091", "this is backend peer 8092"]
["this is backend peer \$TEST_NGINX_RAND_PORT_1", "this is backend peer \$TEST_NGINX_RAND_PORT_2"]
4 changes: 2 additions & 2 deletions t/093-uthread-spawn.t
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ received: OK
content_by_lua '
local function f()
local sock = ngx.socket.udp()
local ok, err = sock:setpeername("127.0.0.1", 12345)
local ok, err = sock:setpeername("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
local bytes, err = sock:send("blah")
if not bytes then
ngx.say("failed to send query: ", err)
Expand Down Expand Up @@ -1002,7 +1002,7 @@ delete thread 2
delete thread 1
)$

--- udp_listen: 12345
--- udp_listen: $TEST_NGINX_RAND_PORT_1
--- udp_query: blah
--- udp_reply: hello udp
--- response_body_like chop
Expand Down
4 changes: 2 additions & 2 deletions t/106-timer.t
Original file line number Diff line number Diff line change
Expand Up @@ -2210,8 +2210,8 @@ qr/\[lua\] content_by_lua\(nginx\.conf:\d+\):\d+: elapsed: .*?, context: ngx\.ti
';
}
--- log_level: error
--- error_log_file: syslog:server=127.0.0.1:12345
--- udp_listen: 12345
--- error_log_file: syslog:server=127.0.0.1:$TEST_NGINX_RAND_PORT_1
--- udp_listen: $TEST_NGINX_RAND_PORT_1
--- udp_query eval: qr/Bad bad bad/
--- udp_reply: hello
--- wait: 0.1
Expand Down
4 changes: 2 additions & 2 deletions t/124-init-worker.t
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ ok
';
}
--- log_level: error
--- error_log_file: syslog:server=127.0.0.1:12345
--- udp_listen: 12345
--- error_log_file: syslog:server=127.0.0.1:$TEST_NGINX_RAND_PORT_1
--- udp_listen: $TEST_NGINX_RAND_PORT_1
--- udp_query eval: qr/Bad bad bad/
--- udp_reply: hello
--- wait: 0.1
Expand Down
4 changes: 1 addition & 3 deletions t/129-ssl-socket.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repeat_each(2);

sub resolve($$);

plan tests => repeat_each() * (blocks() * 7 - 3);
plan tests => repeat_each() * (blocks() * 7 - 4);

$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
Expand Down Expand Up @@ -2141,8 +2141,6 @@ failed to do SSL handshake: timeout
--- log_level: debug
--- grep_error_log eval: qr/lua ssl (?:set|save|free) session: [0-9A-F]+/
--- grep_error_log_out
--- error_log
lua ssl server name: "openresty.org"
--- no_error_log
SSL reused session
[error]
Expand Down
4 changes: 2 additions & 2 deletions t/139-ssl-cert-by.t
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ qr/\[info\] .*? SSL_do_handshake\(\) failed\b/,
lua_package_path "../lua-resty-core/lib/?.lua;;";

server {
listen 127.0.0.1:12345 ssl;
listen 127.0.0.1:$TEST_NGINX_RAND_PORT_1 ssl;
server_name test.com;

ssl_certificate_by_lua_block {
Expand Down Expand Up @@ -1917,7 +1917,7 @@ qr/\[info\] .*? SSL_do_handshake\(\) failed\b/,

sock:settimeout(2000)

local ok, err = sock:connect("127.0.0.1", 12345)
local ok, err = sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
if not ok then
ngx.say("failed to connect: ", err)
return
Expand Down
4 changes: 2 additions & 2 deletions t/163-exit-worker-hup.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ log from exit_worker_by_lua_block
}

server {
listen 12345;
listen $TEST_NGINX_RAND_PORT_1;

location = /t {
echo 'hello world';
Expand All @@ -68,7 +68,7 @@ log from exit_worker_by_lua_block
content_by_lua_block {
ngx.timer.at(0, function ()
local sock = ngx.socket.tcp()
sock:connect("127.0.0.1", 12345)
sock:connect("127.0.0.1", $TEST_NGINX_RAND_PORT_1)
local reader = sock:receiveuntil("unknow")
ngx.log(ngx.NOTICE, "reading to block the exiting")
reader()
Expand Down
Loading

0 comments on commit 766b7a8

Please sign in to comment.