[PATCH 1 of 5] Tests: removed usage of "cat" and "grep" in tests
# HG changeset patch # User Maxim Dounin # Date 1723169931 -10800 # Fri Aug 09 05:18:51 2024 +0300 # Node ID d329b05e20faf1fa7235d95657649f224e46edd4 # Parent e9235c647f45bc6a333fccbbc0d4e8f6d0ea716a Tests: removed usage of "cat" and "grep" in tests. Both "cat" and "grep" might not be available on Windows. Instead, $t->read_file() is used, as it is already used in other places. To simplify checking logs as previously done with "grep", $t->grep_file() helper function is introduced. diff --git a/grpc_request_buffering.t b/grpc_request_buffering.t --- a/grpc_request_buffering.t +++ b/grpc_request_buffering.t @@ -105,7 +105,7 @@ is(eval(join '+', map { $_->{length} } g is(eval(join '+', map { $_->{length} } grep { $_->{type} eq "DATA" } @$frames), 465, 'preserve_output - last body bytes'); -like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crits'); +is($t->grep_file('error.log', '[crit]'), '', 'no crit'); ### diff --git a/h3_ssl_session_reuse.t b/h3_ssl_session_reuse.t --- a/h3_ssl_session_reuse.t +++ b/h3_ssl_session_reuse.t @@ -151,7 +151,7 @@ is(test_reuse(8949), 0, 'cache off not r $t->stop(); -like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit'); +is($t->grep_file('error.log', '[crit]'), '', 'no crit'); ### diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -84,14 +84,12 @@ sub DESTROY { } if (Test::More->builder->expected_tests) { - my $errors = $self->read_file('error.log'); - $errors = join "\n", $errors =~ /.+Sanitizer.+/gm; + my $errors = $self->grep_file('error.log', 'Sanitizer'); Test::More::is($errors, '', 'no sanitizer errors'); } if (Test::More->builder->expected_tests && $ENV{TEST_NGINX_VALGRIND}) { - my $errors = $self->read_file('valgrind.log'); - $errors = join "\n", $errors =~ /^==\d+== .+/gm; + my $errors = $self->grep_file('valgrind.log', /^==\d+== .+/m); Test::More::is($errors, '', 'no valgrind errors'); } @@ -633,6 +631,16 @@ sub read_file($) { return $content; } +sub grep_file($$) { + my ($self, $name, $regex) = @_; + + my $lines = $self->read_file($name); + + $regex = qr/.*\Q$regex\E.*/m if ref($regex) eq ''; + + return join "\n", $lines =~ /$regex/g; +} + sub write_file($$) { my ($self, $name, $content) = @_; diff --git a/memcached_fake.t b/memcached_fake.t --- a/memcached_fake.t +++ b/memcached_fake.t @@ -69,7 +69,7 @@ like(http_get('/'), qr/SEE-THIS/, 'memca like(http_get('/ssi.html'), qr/SEE-THIS/, 'memcached ssi var'); -like(`grep -F '[error]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no errors'); +is($t->grep_file('error.log', '[error]'), '', 'no errors'); ### diff --git a/post_action.t b/post_action.t --- a/post_action.t +++ b/post_action.t @@ -76,6 +76,6 @@ unlike(http_get('/remote'), qr/HIDDEN/m, $t->stop(); -like(`cat ${\($t->testdir())}/access.log`, qr/post/, 'post action in logs'); +like($t->read_file('access.log'), qr/post/, 'post action in logs'); ### diff --git a/proxy_cache_vary.t b/proxy_cache_vary.t --- a/proxy_cache_vary.t +++ b/proxy_cache_vary.t @@ -293,7 +293,7 @@ like(get1('/cold?vary=x,y&xtra=1', 'x:2' $t->stop(); -like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit'); +is($t->grep_file('error.log', '[crit]'), '', 'no crit'); ### diff --git a/proxy_keepalive.t b/proxy_keepalive.t --- a/proxy_keepalive.t +++ b/proxy_keepalive.t @@ -208,7 +208,7 @@ like(http_get('/inmemory/closed2'), qr/2 # check for errors, shouldn't be any -like(`grep -F '[error]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no errors'); +is($t->grep_file('error.log', '[error]'), '', 'no errors'); ### diff --git a/ssl.t b/ssl.t --- a/ssl.t +++ b/ssl.t @@ -275,7 +275,7 @@ is(get_ssl_shutdown(8085), 1, 'ssl shutd like($t->read_file('ssl.log'), qr/^(TLS|SSL)v(\d|\.)+$/m, 'log ssl variable on lingering close'); -like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit'); +is($t->grep_file('error.log', '[crit]'), '', 'no crit'); ### diff --git a/ssl_ocsp.t b/ssl_ocsp.t --- a/ssl_ocsp.t +++ b/ssl_ocsp.t @@ -409,7 +409,7 @@ like(get('root', port => 8447), qr/200 O # check for errors -like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit');
[PATCH 2 of 5] Tests: fixed mail_oauth.t to run with CPU cache line size 32
# HG changeset patch # User Maxim Dounin # Date 1723169931 -10800 # Fri Aug 09 05:18:51 2024 +0300 # Node ID 099c972fb42b7527d13c12765a47e9ae856bbe14 # Parent d329b05e20faf1fa7235d95657649f224e46edd4 Tests: fixed mail_oauth.t to run with CPU cache line size 32. diff --git a/mail_oauth.t b/mail_oauth.t --- a/mail_oauth.t +++ b/mail_oauth.t @@ -65,6 +65,8 @@ mail { http { %%TEST_GLOBALS_HTTP%% +map_hash_bucket_size 64; + map $http_auth_protocol $proxy_port { imap %%PORT_8144%%; pop3 %%PORT_8111%%;
[PATCH 5 of 5] Tests: adjusted proxy_cache_use_stale.t cache validity
# HG changeset patch # User Maxim Dounin # Date 1723217845 -10800 # Fri Aug 09 18:37:25 2024 +0300 # Node ID 15f538440a7734a57353054f2f2e33808f8a1174 # Parent 6b3b31149551efb88fa863901563932c19679db2 Tests: adjusted proxy_cache_use_stale.t cache validity. At least the "s-w-r - updating stale" test sometimes fails on slow hosts due to "stale-while-revalidate=4" being not enough, so the request returns with the EXPIRED cache status instead of STALE. Fix is to use larger "stale-while-revalidate=" times where it is not significant. diff --git a/proxy_cache_use_stale.t b/proxy_cache_use_stale.t --- a/proxy_cache_use_stale.t +++ b/proxy_cache_use_stale.t @@ -163,9 +163,9 @@ like(http_get('/t2.html'), qr/HIT/, 's-w get('/tt.html', 'max-age=1, stale-if-error=3'); get('/t3.html', 'max-age=1, stale-while-revalidate=2'); -get('/t4.html', 'max-age=1, stale-while-revalidate=3'); -get('/t5.html', 'max-age=1, stale-while-revalidate=3'); -get('/t6.html', 'max-age=1, stale-while-revalidate=4'); +get('/t4.html', 'max-age=1, stale-while-revalidate=10'); +get('/t5.html', 'max-age=1, stale-while-revalidate=10'); +get('/t6.html', 'max-age=1, stale-while-revalidate=10'); get('/t7.html', 'max-age=1, stale-while-revalidate=10'); http_get('/ssi.html'); get('/updating/t.html', 'max-age=1');
[PATCH 4 of 5] Tests: removed remnants of "listen ... http2" usage
# HG changeset patch # User Maxim Dounin # Date 1723170064 -10800 # Fri Aug 09 05:21:04 2024 +0300 # Node ID 6b3b31149551efb88fa863901563932c19679db2 # Parent d2d00eea7b3d5bcc39b52df2293481a073156a37 Tests: removed remnants of "listen ... http2" usage. The only remaining test which uses "listen ... http2" is h2_http2.t now, which is specifically to test that this form still works. diff --git a/h2_ssl.t b/h2_ssl.t --- a/h2_ssl.t +++ b/h2_ssl.t @@ -41,9 +41,11 @@ http { %%TEST_GLOBALS_HTTP%% server { -listen 127.0.0.1:8080 http2 ssl; +listen 127.0.0.1:8080 ssl; server_name localhost; +http2 on; + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; @@ -77,9 +79,7 @@ foreach my $name ('localhost') { $t->write_file('tbig.html', join('', map { sprintf "XX%06dXX", $_ } (1 .. 50))); -open OLDERR, ">&", \*STDERR; close STDERR; $t->run(); -open STDERR, ">&", \*OLDERR; plan(skip_all => 'no ALPN negotiation') unless defined getconn(); $t->plan(4); diff --git a/h2_ssl_proxy_cache.t b/h2_ssl_proxy_cache.t --- a/h2_ssl_proxy_cache.t +++ b/h2_ssl_proxy_cache.t @@ -42,9 +42,11 @@ http { proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m; server { -listen 127.0.0.1:8080 http2 ssl sndbuf=32k; +listen 127.0.0.1:8080 ssl sndbuf=32k; server_name localhost; +http2 on; + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; @@ -88,9 +90,7 @@ foreach my $name ('localhost') { $t->write_file('tbig.html', join('', map { sprintf "XX%06dXX", $_ } (1 .. 50))); -open OLDERR, ">&", \*STDERR; close STDERR; $t->run(); -open STDERR, ">&", \*OLDERR; plan(skip_all => 'no ALPN negotiation') unless defined getconn(port(8080)); $t->plan(1); diff --git a/h2_ssl_proxy_protocol.t b/h2_ssl_proxy_protocol.t --- a/h2_ssl_proxy_protocol.t +++ b/h2_ssl_proxy_protocol.t @@ -42,9 +42,11 @@ http { %%TEST_GLOBALS_HTTP%% server { -listen 127.0.0.1:8080 proxy_protocol http2 ssl; +listen 127.0.0.1:8080 proxy_protocol ssl; server_name localhost; +http2 on; + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; @@ -79,9 +81,7 @@ foreach my $name ('localhost') { $t->write_file('t.html', 'SEE-THIS'); -open OLDERR, ">&", \*STDERR; close STDERR; $t->run(); -open STDERR, ">&", \*OLDERR; ### diff --git a/h2_ssl_variables.t b/h2_ssl_variables.t --- a/h2_ssl_variables.t +++ b/h2_ssl_variables.t @@ -39,9 +39,11 @@ http { %%TEST_GLOBALS_HTTP%% server { -listen 127.0.0.1:8080 http2 ssl; +listen 127.0.0.1:8080 ssl; server_name localhost; +http2 on; + ssl_certificate_key localhost.key; ssl_certificate localhost.crt; @@ -80,9 +82,7 @@ foreach my $name ('localhost') { or die "Can't create certificate for $name: $!\n"; } -open OLDERR, ">&", \*STDERR; close STDERR; $t->run(); -open STDERR, ">&", \*OLDERR; ###
[PATCH 3 of 5] Tests: removed remnants of NPN in tests
# HG changeset patch # User Maxim Dounin # Date 1723169932 -10800 # Fri Aug 09 05:18:52 2024 +0300 # Node ID d2d00eea7b3d5bcc39b52df2293481a073156a37 # Parent 099c972fb42b7527d13c12765a47e9ae856bbe14 Tests: removed remnants of NPN in tests. NPN support was removed in nginx 1.21.4 (7934:61abb35bb8cf). diff --git a/h2_ssl_proxy_cache.t b/h2_ssl_proxy_cache.t --- a/h2_ssl_proxy_cache.t +++ b/h2_ssl_proxy_cache.t @@ -92,7 +92,7 @@ open OLDERR, ">&", \*STDERR; close STDER $t->run(); open STDERR, ">&", \*OLDERR; -plan(skip_all => 'no ALPN/NPN negotiation') unless defined getconn(port(8080)); +plan(skip_all => 'no ALPN negotiation') unless defined getconn(port(8080)); $t->plan(1); ### @@ -129,15 +129,6 @@ sub getconn { if $sock->alpn_selected(); }; - return $s if defined $s; - - eval { - my $sock = Test::Nginx::HTTP2::new_socket($port, SSL => 1, - npn => 'h2'); - $s = Test::Nginx::HTTP2->new($port, socket => $sock) - if $sock->next_proto_negotiated(); - }; - return $s; } diff --git a/h2_ssl_variables.t b/h2_ssl_variables.t --- a/h2_ssl_variables.t +++ b/h2_ssl_variables.t @@ -24,7 +24,7 @@ select STDERR; $| = 1; select STDOUT; $| = 1; my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 rewrite socket_ssl/) - ->has_daemon('openssl')->plan(8); + ->has_daemon('openssl')->plan(4); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -88,29 +88,13 @@ open STDERR, ">&", \*OLDERR; my ($s, $sid, $frames, $frame); -my $has_npn = eval { Test::Nginx::HTTP2::new_socket(port(8080), SSL => 1, - npn => 'h2')->next_proto_negotiated() }; my $has_alpn = eval { Test::Nginx::HTTP2::new_socket(port(8080), SSL => 1, alpn => 'h2')->alpn_selected() }; -# SSL/TLS connection, NPN - SKIP: { -skip 'OpenSSL NPN support required', 1 unless $has_npn; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/h2' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); +skip 'OpenSSL ALPN support required', 4 unless $has_alpn; -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'h2', 'http variable - npn'); - -} - -# SSL/TLS connection, ALPN - -SKIP: { -skip 'OpenSSL ALPN support required', 1 unless $has_alpn; +# SSL/TLS connection $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); $sid = $s->new_stream({ path => '/h2' }); @@ -119,26 +103,7 @@ skip 'OpenSSL ALPN support required', 1 ($frame) = grep { $_->{type} eq "DATA" } @$frames; is($frame->{data}, 'h2', 'http variable - alpn'); -} - -# $server_protocol - SSL/TLS connection, NPN - -SKIP: { -skip 'OpenSSL NPN support required', 1 unless $has_npn; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/sp' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - npn'); - -} - -# $server_protocol - SSL/TLS connection, ALPN - -SKIP: { -skip 'OpenSSL ALPN support required', 1 unless $has_alpn; +# $server_protocol $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); $sid = $s->new_stream({ path => '/sp' }); @@ -147,26 +112,7 @@ skip 'OpenSSL ALPN support required', 1 ($frame) = grep { $_->{type} eq "DATA" } @$frames; is($frame->{data}, 'HTTP/2.0', 'server_protocol variable - alpn'); -} - -# $scheme - SSL/TLS connection, NPN - -SKIP: { -skip 'OpenSSL NPN support required', 1 unless $has_npn; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/scheme' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'https', 'scheme variable - npn'); - -} - -# $scheme - SSL/TLS connection, ALPN - -SKIP: { -skip 'OpenSSL ALPN support required', 1 unless $has_alpn; +# $scheme $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); $sid = $s->new_stream({ path => '/scheme' }); @@ -175,26 +121,7 @@ skip 'OpenSSL ALPN support required', 1 ($frame) = grep { $_->{type} eq "DATA" } @$frames; is($frame->{data}, 'https', 'scheme variable - alpn'); -} - -# $https - SSL/TLS connection, NPN - -SKIP: { -skip 'OpenSSL NPN support required', 1 unless $has_npn; - -$s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, npn => 'h2'); -$sid = $s->new_stream({ path => '/https' }); -$frames = $s->read(all => [{ sid => $sid, fin => 1 }]); - -($frame) = grep { $_->{type} eq "DATA" } @$frames; -is($frame->{data}, 'on', 'https variable - npn'); - -} - -# $https - SSL/TLS connection, ALPN - -SKIP: { -skip 'OpenSSL ALPN support required', 1 unless $has_alpn; +# $https $s = Test::Nginx::HTTP2->new(port(8080), SSL => 1, alpn => 'h2'); $sid = $s->new