Skip to content

Commit 689a460

Browse files
casimirothibaultcha
andcommitted
tests(*) add suites for client/upstream connection aborts
Co-Authored-By: Thibault Charbonnier <[email protected]>
1 parent fa7c59b commit 689a460

File tree

6 files changed

+251
-1
lines changed

6 files changed

+251
-1
lines changed

t/03-proxy_wasm/hfuncs/102-proxy_send_local_response.t

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ qr/.*? on_request_headers, 2 headers, .*
143143
.*? testing in "RequestHeaders", .*
144144
.*? on_response_headers, 5 headers, .*
145145
.*? on_response_body, 0 bytes, eof: true, .*
146+
.*? on_done.*
146147
.*? on_log.*/
147148
--- no_error_log
148149
[error]
@@ -248,6 +249,7 @@ qr/.*? on_request_headers, 2 headers, .*
248249
.*? testing in "RequestHeaders", .*
249250
.*? on_response_headers, 16 headers, .*
250251
.*? on_response_body, 0 bytes, eof: true, .*
252+
.*? on_done.*
251253
.*? on_log.*/
252254
--- no_error_log
253255
[error]
@@ -467,7 +469,9 @@ qr/.*? on_request_headers, \d+ headers.*
467469
.*? on_response_headers, \d+ headers.*
468470
.*? on_response_body, \d+ bytes, eof: true.*
469471
.*? on_response_body, \d+ bytes, eof: true.*
472+
.*? on_done.*
470473
.*? on_log.*
474+
.*? on_done.*
471475
.*? on_log.*/
472476
--- no_error_log
473477
[error]

t/04-openresty/ffi/103-proxy_wasm_attach.t

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
105105
#\d+ on_response_headers, 5 headers[^#]*
106106
#\d+ on_response_body, 3 bytes, eof: false[^#]*
107107
#\d+ on_response_body, 0 bytes, eof: true[^#]*
108+
#\d+ on_done[^#]*
108109
#\d+ on_log[^#]*$/
109110
--- error_log eval
110111
qr/\[error\] .*? previous plan already attached/
@@ -156,6 +157,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
156157
#\d+ on_response_headers, 5 headers[^#]*
157158
#\d+ on_response_body, 3 bytes, eof: false[^#]*
158159
#\d+ on_response_body, 0 bytes, eof: true[^#]*
160+
#\d+ on_done[^#]*
159161
#\d+ on_log[^#]*$/
160162
--- no_error_log
161163
[error]
@@ -207,6 +209,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
207209
#\d+ on_response_headers, 5 headers[^#]*
208210
#\d+ on_response_body, 3 bytes, eof: false[^#]*
209211
#\d+ on_response_body, 0 bytes, eof: true[^#]*
212+
#\d+ on_done[^#]*
210213
#\d+ on_log[^#]*$/
211214
--- no_error_log
212215
[error]
@@ -258,6 +261,7 @@ qr/^[^#]*#0 on_vm_start[^#]*
258261
#\d+ on_response_headers, 5 headers[^#]*
259262
#\d+ on_response_body, 3 bytes, eof: false[^#]*
260263
#\d+ on_response_body, 0 bytes, eof: true[^#]*
264+
#\d+ on_done[^#]*
261265
#\d+ on_log[^#]*$/
262266
--- no_error_log
263267
[error]
+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker:
2+
3+
use strict;
4+
use lib '.';
5+
use t::TestWasm;
6+
7+
if ($ENV{TEST_NGINX_USE_HUP}) {
8+
plan(skip_all => "unavailable in HUP mode");
9+
10+
} else {
11+
plan tests => repeat_each() * (blocks() * 4);
12+
}
13+
14+
run_tests();
15+
16+
__DATA__
17+
18+
=== TEST 1: client connection abort - wasm_call
19+
Nginx response filters are not invoked on the produced HTTP 499 response.
20+
--- skip_no_debug: 4
21+
--- wasm_modules: ngx_rust_tests
22+
--- tcp_listen: $TEST_NGINX_UNIX_SOCKET
23+
--- tcp_reply eval
24+
sub {
25+
return ["HTTP/1.1 200 OK\r\n",
26+
"Connection: close\r\n",
27+
"Content-Length: 0\r\n",
28+
"\r\n"];
29+
}
30+
--- config
31+
location /t {
32+
wasm_call content ngx_rust_tests log_notice_hello;
33+
wasm_call header_filter ngx_rust_tests log_notice_hello;
34+
wasm_call body_filter ngx_rust_tests log_notice_hello;
35+
proxy_pass http://unix:$TEST_NGINX_UNIX_SOCKET:/;
36+
}
37+
--- shutdown
38+
--- ignore_response
39+
--- grep_error_log eval: qr/(client prematurely closed|(wasm ops calling .*? in .*? phase))/
40+
--- grep_error_log_out eval
41+
qr/wasm ops calling "ngx_rust_tests\.log_notice_hello" in "content" phase
42+
client prematurely closed\Z/
43+
--- no_error_log
44+
header_filter
45+
body_filter
46+
[error]
47+
48+
49+
50+
=== TEST 2: client connection abort - chained filters
51+
Filters on aborted client connections do not execute response phases.
52+
--- wasm_modules: on_phases
53+
--- tcp_listen: $TEST_NGINX_UNIX_SOCKET
54+
--- tcp_reply eval
55+
sub {
56+
return ["HTTP/1.1 200 OK\r\n",
57+
"Connection: close\r\n",
58+
"Content-Length: 0\r\n",
59+
"\r\n"];
60+
}
61+
--- config
62+
location /t {
63+
proxy_wasm on_phases;
64+
proxy_wasm on_phases;
65+
proxy_pass http://unix:$TEST_NGINX_UNIX_SOCKET:/;
66+
}
67+
--- shutdown
68+
--- ignore_response
69+
--- grep_error_log eval: qr/\[info\] .*? ((client prematurely closed)|on_request_headers|on_response_headers|on_log|on_done|on_http_call_response.*)/
70+
--- grep_error_log_out eval
71+
qr/\A\[info\] .*? on_request_headers
72+
\[info\] .*? on_request_headers
73+
\[info\] .*? reported that client prematurely closed
74+
\[info\] .*? on_done
75+
\[info\] .*? on_log
76+
\[info\] .*? on_done
77+
\[info\] .*? on_log\Z/
78+
--- no_error_log
79+
on_response
80+
[error]
81+
[crit]
82+
83+
84+
85+
=== TEST 3: client connection abort - chained filters with HTTP dispatch
86+
Filters with pending dispatch calls on aborted client connections await for
87+
response.
88+
--- load_nginx_modules: ngx_http_echo_module
89+
--- wasm_modules: hostcalls
90+
--- http_config eval
91+
qq{
92+
server {
93+
listen unix:$ENV{TEST_NGINX_UNIX_SOCKET};
94+
95+
location / {
96+
return 200;
97+
}
98+
99+
location /sleep {
100+
echo_sleep 0.3;
101+
echo_status 201;
102+
}
103+
}
104+
}
105+
--- config
106+
location /t {
107+
proxy_wasm hostcalls 'test=/t/dispatch_http_call \
108+
host=unix:$TEST_NGINX_UNIX_SOCKET \
109+
path=/';
110+
proxy_wasm hostcalls 'test=/t/dispatch_http_call \
111+
host=unix:$TEST_NGINX_UNIX_SOCKET \
112+
path=/sleep';
113+
proxy_pass http://unix:$TEST_NGINX_UNIX_SOCKET:/;
114+
}
115+
--- shutdown
116+
--- ignore_response
117+
--- grep_error_log eval: qr/\[info\] .*? ((client prematurely closed)|on_request_headers|on_response_headers|on_log|on_done|on_http_call_response.*)/
118+
--- grep_error_log_out eval
119+
qr/\A\[info\] .*? on_request_headers
120+
\[info\] .*? on_http_call_response \(id: \d+, status: 200[^*].*
121+
\[info\] .*? on_request_headers
122+
\[info\] .*? on_http_call_response \(id: \d+, status: 201[^*].*
123+
\[info\] .*? reported that client prematurely closed
124+
\[info\] .*? on_done
125+
\[info\] .*? on_log
126+
\[info\] .*? on_done
127+
\[info\] .*? on_log\Z/
128+
--- no_error_log
129+
[error]
130+
[crit]
131+
[emerg]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker:
2+
3+
use strict;
4+
use lib '.';
5+
use t::TestWasm;
6+
7+
skip_valgrind();
8+
9+
if ($ENV{TEST_NGINX_USE_HUP}) {
10+
plan(skip_all => "unavailable in HUP mode");
11+
12+
} else {
13+
plan tests => repeat_each() * (blocks() * 4);
14+
}
15+
16+
run_tests();
17+
18+
__DATA__
19+
20+
=== TEST 1: upstream connection abort - wasm_call
21+
Calls on aborted upstream connections execute response phases on the produced
22+
HTTP 502 response.
23+
--- skip_no_debug: 4
24+
--- wasm_modules: ngx_rust_tests
25+
--- tcp_listen: $TEST_NGINX_UNIX_SOCKET
26+
--- tcp_shutdown: 2
27+
--- tcp_reply eval
28+
sub {
29+
return ["HTTP/1.1 100 OK\r\n",
30+
"Connection: close\r\n",
31+
"Content-Length: 0\r\n",
32+
"\r\n"];
33+
}
34+
--- config
35+
location /t {
36+
wasm_call header_filter ngx_rust_tests log_notice_hello;
37+
wasm_call body_filter ngx_rust_tests log_notice_hello;
38+
proxy_pass http://unix:$TEST_NGINX_UNIX_SOCKET:/;
39+
}
40+
--- error_code: 502
41+
--- ignore_response
42+
--- grep_error_log eval: qr/(upstream prematurely closed|(wasm ops calling .*? in .*? phase))/
43+
--- grep_error_log_out eval
44+
qr/\Aupstream prematurely closed
45+
wasm ops calling "ngx_rust_tests\.log_notice_hello" in "header_filter" phase
46+
wasm ops calling "ngx_rust_tests\.log_notice_hello" in "body_filter" phase\Z/
47+
--- no_error_log
48+
[crit]
49+
[emerg]
50+
[alert]
51+
52+
53+
54+
=== TEST 2: upstream connection abort - chained filters
55+
Filters on aborted upstream connections execute response phases on the produced
56+
HTTP 502 response.
57+
--- wasm_modules: on_phases
58+
--- tcp_listen: $TEST_NGINX_UNIX_SOCKET
59+
--- tcp_shutdown: 2
60+
--- tcp_reply eval
61+
sub {
62+
return ["HTTP/1.1 100 OK\r\n",
63+
"Connection: close\r\n",
64+
"Content-Length: 0\r\n",
65+
"\r\n"];
66+
}
67+
--- config
68+
location /t {
69+
proxy_wasm on_phases;
70+
proxy_wasm on_phases;
71+
proxy_pass http://unix:$TEST_NGINX_UNIX_SOCKET:/;
72+
}
73+
--- error_code: 502
74+
--- ignore_response
75+
--- grep_error_log eval: qr/\[(error|info)\] .*? ((upstream prematurely closed)|on_request_headers|on_response_headers|on_log|on_done|on_http_call_response.*)/
76+
--- grep_error_log_out eval
77+
qr/\A\[info\] .*? on_request_headers
78+
\[info\] .*? on_request_headers
79+
\[error\] .*? upstream prematurely closed
80+
\[info\] .*? on_response_headers
81+
\[info\] .*? on_response_headers
82+
\[info\] .*? on_done
83+
\[info\] .*? on_log
84+
\[info\] .*? on_done
85+
\[info\] .*? on_log\Z/
86+
--- no_error_log
87+
[crit]
88+
[emerg]
89+
[alert]

t/lib/proxy-wasm-tests/hostcalls/src/filter.rs

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ impl Context for TestHttp {
105105

106106
self.resume_http_request()
107107
}
108+
109+
fn on_done(&mut self) -> bool {
110+
info!("[hostcalls] on_done");
111+
112+
true
113+
}
108114
}
109115

110116
impl HttpContext for TestHttp {

t/lib/proxy-wasm-tests/on-phases/src/filter.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,23 @@ impl OnPhases {
109109
}
110110
}
111111

112-
impl Context for OnPhases {}
112+
impl Context for OnPhases {
113+
fn on_done(&mut self) -> bool {
114+
info!("#{} on_done", self.context_id);
115+
116+
let log_msg = self
117+
.config
118+
.get("log_msg")
119+
.map_or(String::new(), |s| s.to_string());
120+
121+
if !log_msg.is_empty() {
122+
info!("#{} log_msg: {}", self.context_id, log_msg);
123+
}
124+
125+
true
126+
}
127+
}
128+
113129
impl HttpContext for OnPhases {
114130
fn on_http_request_headers(&mut self, nheaders: usize, _eof: bool) -> Action {
115131
info!(

0 commit comments

Comments
 (0)