annotate lib/Test/Nginx.pm @ 1978:79753dd514e6 default tip

Tests: added test for mail proxy timeout.
author Rob Mueller <robm@fastmailteam.com>
date Wed, 15 May 2024 23:51:31 +0300
parents ab45ee8011df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
1 package Test::Nginx;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
155
33f6ec774efa Tests: fix typo.
Maxim Dounin <mdounin@mdounin.ru>
parents: 144
diff changeset
5 # Generic module for nginx tests.
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use base qw/ Exporter /;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
14 our @EXPORT = qw/ log_in log_out http http_get http_head port /;
1612
8659123d2d37 Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1609
diff changeset
15 our @EXPORT_OK = qw/
8659123d2d37 Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1609
diff changeset
16 http_gzip_request http_gzip_like http_start http_end http_content
8659123d2d37 Tests: made http_content() exportable.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1609
diff changeset
17 /;
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
18 our %EXPORT_TAGS = (
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
19 gzip => [ qw/ http_gzip_request http_gzip_like / ]
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
20 );
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
290
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
24 use File::Path qw/ rmtree /;
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
25 use File::Spec qw//;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26 use File::Temp qw/ tempdir /;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 use IO::Socket;
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
28 use POSIX qw/ waitpid WNOHANG /;
7
9eb509695651 Tests: drop our own CRLF constant, use Socket's one instead.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6
diff changeset
29 use Socket qw/ CRLF /;
27
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
30 use Test::More qw//;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
32 ###############################################################################
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
48
acfafb52d393 Tests: use TEST_NGINX_BINARY to find nginx binary.
Maxim Dounin <mdounin@mdounin.ru>
parents: 46
diff changeset
34 our $NGINX = defined $ENV{TEST_NGINX_BINARY} ? $ENV{TEST_NGINX_BINARY}
acfafb52d393 Tests: use TEST_NGINX_BINARY to find nginx binary.
Maxim Dounin <mdounin@mdounin.ru>
parents: 46
diff changeset
35 : '../nginx/objs/nginx';
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
36 our %ports = ();
27
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
37
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
38 sub new {
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
39 my $self = {};
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
40 bless $self;
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
41
296
a113f4d55b12 Tests: fix hang on exit after errors in child processes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 290
diff changeset
42 $self->{_pid} = $$;
592
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
43 $self->{_alerts} = 1;
296
a113f4d55b12 Tests: fix hang on exit after errors in child processes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 290
diff changeset
44
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
45 $self->{_testdir} = tempdir(
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
46 'nginx-test-XXXXXXXXXX',
290
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
47 TMPDIR => 1
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
48 )
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
49 or die "Can't create temp directory: $!\n";
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
50 $self->{_testdir} =~ s!\\!/!g if $^O eq 'MSWin32';
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
51
460
0342957cca37 Tests: check for nginx binary presence.
Sergey Kandaurov <pluknet@nginx.com>
parents: 438
diff changeset
52 Test::More::BAIL_OUT("no $NGINX binary found")
0342957cca37 Tests: check for nginx binary presence.
Sergey Kandaurov <pluknet@nginx.com>
parents: 438
diff changeset
53 unless -x $NGINX;
0342957cca37 Tests: check for nginx binary presence.
Sergey Kandaurov <pluknet@nginx.com>
parents: 438
diff changeset
54
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
55 return $self;
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
56 }
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
57
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
58 sub DESTROY {
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
59 my ($self) = @_;
415
020c4e47ecac Tests: revert 068d020a8f85 and localize $? instead.
Maxim Dounin <mdounin@mdounin.ru>
parents: 411
diff changeset
60 local $?;
020c4e47ecac Tests: revert 068d020a8f85 and localize $? instead.
Maxim Dounin <mdounin@mdounin.ru>
parents: 411
diff changeset
61
296
a113f4d55b12 Tests: fix hang on exit after errors in child processes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 290
diff changeset
62 return if $self->{_pid} != $$;
415
020c4e47ecac Tests: revert 068d020a8f85 and localize $? instead.
Maxim Dounin <mdounin@mdounin.ru>
parents: 411
diff changeset
63
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
64 $self->stop();
144
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
65 $self->stop_daemons();
415
020c4e47ecac Tests: revert 068d020a8f85 and localize $? instead.
Maxim Dounin <mdounin@mdounin.ru>
parents: 411
diff changeset
66
592
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
67 if (Test::More->builder->expected_tests) {
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
68 local $Test::Nginx::TODO = 'alerts' unless $self->{_alerts};
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
69
891
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
70 my @alerts = $self->read_file('error.log') =~ /.+\[alert\].+/gm;
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
71
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
72 if ($^O eq 'solaris') {
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
73 $Test::Nginx::TODO = 'alerts' if @alerts
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
74 && ! grep { $_ !~ /phantom event/ } @alerts;
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
75 }
918
8d489e743fcb Tests: TODO certain alerts on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 910
diff changeset
76 if ($^O eq 'MSWin32') {
8d489e743fcb Tests: TODO certain alerts on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 910
diff changeset
77 my $re = qr/CloseHandle|TerminateProcess/;
8d489e743fcb Tests: TODO certain alerts on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 910
diff changeset
78 $Test::Nginx::TODO = 'alerts' if @alerts
8d489e743fcb Tests: TODO certain alerts on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 910
diff changeset
79 && ! grep { $_ !~ $re } @alerts;
8d489e743fcb Tests: TODO certain alerts on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 910
diff changeset
80 }
891
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
81
f4189a38c3a4 Tests: mark 'phantom event' alerts on Solaris as TODO (iff any).
Sergey Kandaurov <pluknet@nginx.com>
parents: 865
diff changeset
82 Test::More::is(join("\n", @alerts), '', 'no alerts');
592
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
83 }
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
84
861
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
85 if (Test::More->builder->expected_tests) {
910
49579dd88e3f Tests: localize $Test::Nginx::TODO for sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 891
diff changeset
86 local $Test::Nginx::TODO;
861
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
87 my $errors = $self->read_file('error.log');
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
88 $errors = join "\n", $errors =~ /.+Sanitizer.+/gm;
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
89 Test::More::is($errors, '', 'no sanitizer errors');
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
90 }
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
91
51
d59ae7bab0a6 Tests: cat error log to stdout if TEST_NGINX_CATLOG set.
Maxim Dounin <mdounin@mdounin.ru>
parents: 50
diff changeset
92 if ($ENV{TEST_NGINX_CATLOG}) {
d59ae7bab0a6 Tests: cat error log to stdout if TEST_NGINX_CATLOG set.
Maxim Dounin <mdounin@mdounin.ru>
parents: 50
diff changeset
93 system("cat $self->{_testdir}/error.log");
d59ae7bab0a6 Tests: cat error log to stdout if TEST_NGINX_CATLOG set.
Maxim Dounin <mdounin@mdounin.ru>
parents: 50
diff changeset
94 }
290
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
95 if (not $ENV{TEST_NGINX_LEAVE}) {
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
96 eval { rmtree($self->{_testdir}); };
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
97 }
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
98 }
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
99
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
100 sub has($;) {
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
101 my ($self, @features) = @_;
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
102
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
103 foreach my $feature (@features) {
574
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
104 Test::More::plan(skip_all => "no $feature available")
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
105 unless $self->has_module($feature)
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
106 or $self->has_feature($feature);
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
107 }
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
108
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
109 return $self;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
110 }
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
111
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
112 sub has_module($) {
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
113 my ($self, $feature) = @_;
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
114
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
115 my %regex = (
237
90af19544dd2 Tests: https sni tests.
Valentin Bartenev <ne@vbart.ru>
parents: 232
diff changeset
116 sni => 'TLS SNI support enabled',
1971
ab45ee8011df Tests: guarded session ticket tests for old OpenSSL versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1970
diff changeset
117 tickets => 'TLS SNI support enabled',
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
118 mail => '--with-mail((?!\S)|=dynamic)',
33
4f57d57543e1 Tests: range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 29
diff changeset
119 flv => '--with-http_flv_module',
118
4bf7a819358c Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 107
diff changeset
120 perl => '--with-http_perl_module',
323
d48de852157c Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents: 312
diff changeset
121 auth_request
d48de852157c Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents: 312
diff changeset
122 => '--with-http_auth_request_module',
1035
c0accd6fab6c Tests: distinguished realip and stream_ssl prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1027
diff changeset
123 realip => '--with-http_realip_module',
1133
9edf2f99c58f Tests: fixed has() check for sub filter tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1081
diff changeset
124 sub => '--with-http_sub_module',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
125 charset => '(?s)^(?!.*--without-http_charset_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
126 gzip => '(?s)^(?!.*--without-http_gzip_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
127 ssi => '(?s)^(?!.*--without-http_ssi_module)',
1208
a6453cf5786a Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1206
diff changeset
128 mirror => '(?s)^(?!.*--without-http_mirror_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
129 userid => '(?s)^(?!.*--without-http_userid_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
130 access => '(?s)^(?!.*--without-http_access_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
131 auth_basic
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
132 => '(?s)^(?!.*--without-http_auth_basic_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
133 autoindex
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
134 => '(?s)^(?!.*--without-http_autoindex_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
135 geo => '(?s)^(?!.*--without-http_geo_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
136 map => '(?s)^(?!.*--without-http_map_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
137 referer => '(?s)^(?!.*--without-http_referer_module)',
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
138 rewrite => '(?s)^(?!.*--without-http_rewrite_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
139 proxy => '(?s)^(?!.*--without-http_proxy_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
140 fastcgi => '(?s)^(?!.*--without-http_fastcgi_module)',
139
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
141 uwsgi => '(?s)^(?!.*--without-http_uwsgi_module)',
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
142 scgi => '(?s)^(?!.*--without-http_scgi_module)',
1302
beed8146d045 Tests: grpc module prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1263
diff changeset
143 grpc => '(?s)^(?!.*--without-http_grpc_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
144 memcached
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
145 => '(?s)^(?!.*--without-http_memcached_module)',
312
b639e76ba923 Tests: limit_zone regex updated to follow the module renaming.
Sergey Kandaurov <pluknet@nginx.com>
parents: 296
diff changeset
146 limit_conn
b639e76ba923 Tests: limit_zone regex updated to follow the module renaming.
Sergey Kandaurov <pluknet@nginx.com>
parents: 296
diff changeset
147 => '(?s)^(?!.*--without-http_limit_conn_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
148 limit_req
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
149 => '(?s)^(?!.*--without-http_limit_req_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
150 empty_gif
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
151 => '(?s)^(?!.*--without-http_empty_gif_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
152 browser => '(?s)^(?!.*--without-http_browser_module)',
411
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 395
diff changeset
153 upstream_hash
17c5a1cc8757 Tests: upstream hash tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 395
diff changeset
154 => '(?s)^(?!.*--without-http_upstream_hash_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
155 upstream_ip_hash
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
156 => '(?s)^(?!.*--without-http_upstream_ip_hash_module)',
275
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
157 upstream_least_conn
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
158 => '(?s)^(?!.*--without-http_upstream_least_conn_mod)',
1350
fda743e92b31 Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1308
diff changeset
159 upstream_random
fda743e92b31 Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1308
diff changeset
160 => '(?s)^(?!.*--without-http_upstream_random_module)',
275
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
161 upstream_keepalive
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
162 => '(?s)^(?!.*--without-http_upstream_keepalive_modu)',
560
f3434de79a7f Tests: upstream zone tests with ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents: 557
diff changeset
163 upstream_zone
f3434de79a7f Tests: upstream zone tests with ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents: 557
diff changeset
164 => '(?s)^(?!.*--without-http_upstream_zone_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
165 http => '(?s)^(?!.*--without-http(?!\S))',
106
7a712d3909ba Tests: add cache availability checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 104
diff changeset
166 cache => '(?s)^(?!.*--without-http-cache)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
167 pop3 => '(?s)^(?!.*--without-mail_pop3_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
168 imap => '(?s)^(?!.*--without-mail_imap_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
169 smtp => '(?s)^(?!.*--without-mail_smtp_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
170 pcre => '(?s)^(?!.*--without-pcre)',
348
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 339
diff changeset
171 split_clients
08bb2b3785a2 Tests: added basic test for split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 339
diff changeset
172 => '(?s)^(?!.*--without-http_split_clients_module)',
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
173 stream => '--with-stream((?!\S)|=dynamic)',
977
6abe7be6d2c1 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 973
diff changeset
174 stream_access
6abe7be6d2c1 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 973
diff changeset
175 => '(?s)^(?!.*--without-stream_access_module)',
978
04cb1849005a Tests: basic tests for stream geo module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 977
diff changeset
176 stream_geo
04cb1849005a Tests: basic tests for stream geo module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 977
diff changeset
177 => '(?s)^(?!.*--without-stream_geo_module)',
620
7497adad1a50 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 619
diff changeset
178 stream_limit_conn
7497adad1a50 Tests: style.
Sergey Kandaurov <pluknet@nginx.com>
parents: 619
diff changeset
179 => '(?s)^(?!.*--without-stream_limit_conn_module)',
963
c26b0eaed67a Tests: stream return and map modules prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 957
diff changeset
180 stream_map
c26b0eaed67a Tests: stream return and map modules prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 957
diff changeset
181 => '(?s)^(?!.*--without-stream_map_module)',
c26b0eaed67a Tests: stream return and map modules prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 957
diff changeset
182 stream_return
c26b0eaed67a Tests: stream return and map modules prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 957
diff changeset
183 => '(?s)^(?!.*--without-stream_return_module)',
1593
a328109be893 Tests: stream set tests.
Vladimir Kokshenev <v.kokshenev@f5.com>
parents: 1350
diff changeset
184 stream_set
a328109be893 Tests: stream set tests.
Vladimir Kokshenev <v.kokshenev@f5.com>
parents: 1350
diff changeset
185 => '(?s)^(?!.*--without-stream_set_module)',
979
ef6be3201851 Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 978
diff changeset
186 stream_split_clients
ef6be3201851 Tests: basic tests for stream split_clients module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 978
diff changeset
187 => '(?s)^(?!.*--without-stream_split_clients_module)',
1035
c0accd6fab6c Tests: distinguished realip and stream_ssl prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1027
diff changeset
188 stream_ssl
c0accd6fab6c Tests: distinguished realip and stream_ssl prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1027
diff changeset
189 => '--with-stream_ssl_module',
571
5c3946ebd867 Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents: 560
diff changeset
190 stream_upstream_hash
5c3946ebd867 Tests: basic stream tests for upstream hash.
Sergey Kandaurov <pluknet@nginx.com>
parents: 560
diff changeset
191 => '(?s)^(?!.*--without-stream_upstream_hash_module)',
557
05cbe9e2def8 Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents: 552
diff changeset
192 stream_upstream_least_conn
05cbe9e2def8 Tests: basic stream tests for upstream least_conn.
Sergey Kandaurov <pluknet@nginx.com>
parents: 552
diff changeset
193 => '(?s)^(?!.*--without-stream_upstream_least_conn_m)',
1350
fda743e92b31 Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1308
diff changeset
194 stream_upstream_random
fda743e92b31 Tests: upstream random tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1308
diff changeset
195 => '(?s)^(?!.*--without-stream_upstream_random_modul)',
560
f3434de79a7f Tests: upstream zone tests with ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents: 557
diff changeset
196 stream_upstream_zone
f3434de79a7f Tests: upstream zone tests with ssl backend.
Sergey Kandaurov <pluknet@nginx.com>
parents: 557
diff changeset
197 => '(?s)^(?!.*--without-stream_upstream_zone_module)',
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
198 );
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
199
100
9ddc18214854 Tests: arbitrary regexp support in has().
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
200 my $re = $regex{$feature};
9ddc18214854 Tests: arbitrary regexp support in has().
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
201 $re = $feature if !defined $re;
9ddc18214854 Tests: arbitrary regexp support in has().
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
202
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
203 $self->{_configure_args} = `$NGINX -V 2>&1`
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
204 if !defined $self->{_configure_args};
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
205
1042
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
206 return 1 if $self->{_configure_args} =~ $re;
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
207
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
208 my %modules = (
1063
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
209 http_geoip
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
210 => 'ngx_http_geoip_module',
1042
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
211 image_filter
1053
fbf731526f49 Tests: relaxed check for known dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1045
diff changeset
212 => 'ngx_http_image_filter_module',
fbf731526f49 Tests: relaxed check for known dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1045
diff changeset
213 perl => 'ngx_http_perl_module',
fbf731526f49 Tests: relaxed check for known dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1045
diff changeset
214 xslt => 'ngx_http_xslt_filter_module',
fbf731526f49 Tests: relaxed check for known dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1045
diff changeset
215 mail => 'ngx_mail_module',
fbf731526f49 Tests: relaxed check for known dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1045
diff changeset
216 stream => 'ngx_stream_module',
1063
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
217 stream_geoip
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
218 => 'ngx_stream_geoip_module',
1042
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
219 );
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
220
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
221 my $module = $modules{$feature};
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
222 if (defined $module && defined $ENV{TEST_NGINX_GLOBALS}) {
1053
fbf731526f49 Tests: relaxed check for known dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1045
diff changeset
223 $re = qr/load_module\s+[^;]*\Q$module\E[-\w]*\.so\s*;/;
1042
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
224 return 1 if $ENV{TEST_NGINX_GLOBALS} =~ $re;
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
225 }
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
226
9339673bb454 Tests: check for known dynamic modules via TEST_NGINX_GLOBALS.
Andrei Belov <defan@nginx.com>
parents: 1035
diff changeset
227 return 0;
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
228 }
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
229
574
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
230 sub has_feature($) {
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
231 my ($self, $feature) = @_;
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
232
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
233 if ($feature eq 'symlink') {
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
234 return $^O ne 'MSWin32';
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
235 }
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
236
800
51d3243a762f Tests: skip tests with unix domain sockets on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 778
diff changeset
237 if ($feature eq 'unix') {
51d3243a762f Tests: skip tests with unix domain sockets on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 778
diff changeset
238 return $^O ne 'MSWin32';
51d3243a762f Tests: skip tests with unix domain sockets on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 778
diff changeset
239 }
51d3243a762f Tests: skip tests with unix domain sockets on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 778
diff changeset
240
947
b9e42c554ba7 Tests: skip UDP tests on win32, udp feature introduced.
Sergey Kandaurov <pluknet@nginx.com>
parents: 918
diff changeset
241 if ($feature eq 'udp') {
b9e42c554ba7 Tests: skip UDP tests on win32, udp feature introduced.
Sergey Kandaurov <pluknet@nginx.com>
parents: 918
diff changeset
242 return $^O ne 'MSWin32';
b9e42c554ba7 Tests: skip UDP tests on win32, udp feature introduced.
Sergey Kandaurov <pluknet@nginx.com>
parents: 918
diff changeset
243 }
b9e42c554ba7 Tests: skip UDP tests on win32, udp feature introduced.
Sergey Kandaurov <pluknet@nginx.com>
parents: 918
diff changeset
244
1858
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
245 if ($feature =~ /^socket_ssl/) {
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
246 eval { require IO::Socket::SSL; };
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
247 return 0 if $@;
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
248 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
249 return 0 if $@;
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
250 if ($feature eq 'socket_ssl') {
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
251 return 1;
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
252 }
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
253 if ($feature eq 'socket_ssl_sni') {
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
254 eval { IO::Socket::SSL->can_client_sni() or die; };
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
255 return !$@;
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
256 }
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
257 if ($feature eq 'socket_ssl_alpn') {
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
258 eval { IO::Socket::SSL->can_alpn() or die; };
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
259 return !$@;
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
260 }
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
261 if ($feature eq 'socket_ssl_sslversion') {
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
262 return IO::Socket::SSL->can('get_sslversion');
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
263 }
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
264 if ($feature eq 'socket_ssl_reused') {
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
265 return IO::Socket::SSL->can('get_session_reused');
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
266 }
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
267 return 0;
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
268 }
cdcd75657e52 Tests: added has_feature() tests for IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1790
diff changeset
269
1921
07656d303199 Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1896
diff changeset
270 if ($feature =~ /^(openssl|libressl):([0-9.]+)([a-z]*)/) {
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
271 my $library = $1;
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
272 my $need = $2;
1921
07656d303199 Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1896
diff changeset
273 my $patch = $3;
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
274
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
275 $self->{_configure_args} = `$NGINX -V 2>&1`
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
276 if !defined $self->{_configure_args};
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
277
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
278 return 0 unless
1921
07656d303199 Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1896
diff changeset
279 $self->{_configure_args}
07656d303199 Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1896
diff changeset
280 =~ /with $library ([0-9.]+)([a-z]*)/i;
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
281
1921
07656d303199 Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1896
diff changeset
282 my @v = (split(/\./, $1), unpack("C*", $2));
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
283 my ($n, $v);
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
284
1921
07656d303199 Tests: adjusted TODO for OpenSSL 1.0.2h and up in h2_http2.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1896
diff changeset
285 for $n (split(/\./, $need), unpack("C*", $patch)) {
1860
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
286 $v = shift @v || 0;
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
287 return 0 if $n > $v;
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
288 return 1 if $v > $n;
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
289 }
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
290
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
291 return 1;
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
292 }
58951cf933e1 Tests: added has_feature() test for SSL libraries.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1858
diff changeset
293
1896
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
294 if ($feature eq 'cryptx') {
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
295 eval { require Crypt::Misc; };
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
296 return 0 if $@;
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
297 eval { die if $Crypt::Misc::VERSION < 0.067; };
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
298 return !$@;
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
299 }
8b74936ff2ac Tests: added has_feature() test for CryptX.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1865
diff changeset
300
574
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
301 return 0;
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
302 }
2cd00179f4b2 Tests: has_feature() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 571
diff changeset
303
242
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
304 sub has_version($) {
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
305 my ($self, $need) = @_;
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
306
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
307 $self->{_configure_args} = `$NGINX -V 2>&1`
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
308 if !defined $self->{_configure_args};
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
309
1947
1d980c5013dc Tests: improved version detection to accept alternative names.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1921
diff changeset
310 $self->{_configure_args} =~ m!nginx version: \w+/([0-9.]+)!;
242
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
311
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
312 my @v = split(/\./, $1);
284
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
313 my ($n, $v);
242
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
314
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
315 for $n (split(/\./, $need)) {
284
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
316 $v = shift @v || 0;
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
317 return 0 if $n > $v;
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
318 return 1 if $v > $n;
242
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
319 }
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
320
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
321 return 1;
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
322 }
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
323
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
324 sub has_daemon($) {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
325 my ($self, $daemon) = @_;
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
326
220
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
327 if ($^O eq 'MSWin32') {
1221
852856f8e7dc Tests: added has_daemon() support for win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1208
diff changeset
328 `for %i in ($daemon.exe) do \@echo | set /p x=%~\$PATH:i`
852856f8e7dc Tests: added has_daemon() support for win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1208
diff changeset
329 or Test::More::plan(skip_all => "$daemon not found");
220
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
330 return $self;
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
331 }
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
332
232
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
333 if ($^O eq 'solaris') {
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
334 Test::More::plan(skip_all => "$daemon not found")
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
335 unless `command -v $daemon`;
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
336 return $self;
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
337 }
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
338
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
339 Test::More::plan(skip_all => "$daemon not found")
1963
5656138f2e46 Tests: improved has_daemon() to drop "which" stderr.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1947
diff changeset
340 unless `which $daemon 2>/dev/null`;
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
341
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
342 return $self;
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
343 }
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
344
392
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
345 sub try_run($$) {
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
346 my ($self, $message) = @_;
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
347
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
348 eval {
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
349 open OLDERR, ">&", \*STDERR; close STDERR;
392
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
350 $self->run();
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
351 open STDERR, ">&", \*OLDERR;
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
352 };
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
353
1238
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
354 return $self unless $@;
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
355
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
356 if ($ENV{TEST_NGINX_VERBOSE}) {
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
357 open F, '<', $self->{_testdir} . '/error.log'
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
358 or die "Can't open error.log: $!";
1238
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
359 log_core($_) while (<F>);
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
360 close F;
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
361 }
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
362
e35cc79ed4a1 Tests: show try_run() errors in verbose mode.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1236
diff changeset
363 Test::More::plan(skip_all => $message);
392
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
364 return $self;
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
365 }
c28ecaef065f Tests: try_run() introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents: 375
diff changeset
366
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
367 sub plan($) {
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
368 my ($self, $plan) = @_;
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
369
861
6868e610eacc Tests: detect Sanitizer errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 856
diff changeset
370 Test::More::plan(tests => $plan + 2);
592
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
371
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
372 return $self;
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
373 }
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
374
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
375 sub todo_alerts() {
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
376 my ($self) = @_;
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
377
355f2d5ff60f Tests: catch nginx alerts on exit.
Sergey Kandaurov <pluknet@nginx.com>
parents: 574
diff changeset
378 $self->{_alerts} = 0;
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
379
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
380 return $self;
27
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
381 }
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
382
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
383 sub run(;$) {
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
384 my ($self, $conf) = @_;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
385
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
386 my $testdir = $self->{_testdir};
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
387
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
388 if (defined $conf) {
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
389 my $c = `cat $conf`;
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
390 $self->write_file_expand('nginx.conf', $c);
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
391 }
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
392
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
393 my $pid = fork();
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
394 die "Unable to fork(): $!\n" unless defined $pid;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
395
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
396 if ($pid == 0) {
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
397 my @globals = $self->{_test_globals} ?
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
398 () : ('-g', "pid $testdir/nginx.pid; "
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
399 . "error_log $testdir/error.log debug;");
1630
6f573329e862 Tests: "-e" command line option support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1629
diff changeset
400 exec($NGINX, '-p', "$testdir/", '-c', 'nginx.conf',
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
401 '-e', 'error.log', @globals)
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
402 or die "Unable to exec(): $!\n";
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
403 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
404
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
405 # wait for nginx to start
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
406
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
407 $self->waitforfile("$testdir/nginx.pid", $pid)
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
408 or die "Can't start nginx";
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
409
1263
ea3c7659b6c1 Tests: handled early pidfile write on win32 in the run() routine.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1238
diff changeset
410 for (1 .. 50) {
ea3c7659b6c1 Tests: handled early pidfile write on win32 in the run() routine.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1238
diff changeset
411 last if $^O ne 'MSWin32';
ea3c7659b6c1 Tests: handled early pidfile write on win32 in the run() routine.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1238
diff changeset
412 last if $self->read_file('error.log') =~ /create thread/;
ea3c7659b6c1 Tests: handled early pidfile write on win32 in the run() routine.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1238
diff changeset
413 select undef, undef, undef, 0.1;
ea3c7659b6c1 Tests: handled early pidfile write on win32 in the run() routine.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1238
diff changeset
414 }
ea3c7659b6c1 Tests: handled early pidfile write on win32 in the run() routine.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1238
diff changeset
415
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
416 $self->{_started} = 1;
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
417 return $self;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
418 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
419
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
420 sub port {
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
421 my ($num, %opts) = @_;
1236
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
422 my ($sock, $lock, $port);
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
423
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
424 goto done if defined $ports{$num};
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
425
1236
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
426 my $socket = sub {
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
427 IO::Socket::INET->new(
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
428 Proto => 'tcp',
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
429 LocalAddr => '127.0.0.1:' . shift,
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
430 Listen => 1,
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
431 Reuse => ($^O ne 'MSWin32'),
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
432 );
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
433 };
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
434
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
435 my $socketl = sub {
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
436 IO::Socket::INET->new(
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
437 Proto => 'udp',
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
438 LocalAddr => '127.0.0.1:' . shift,
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
439 );
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
440 };
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
441
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
442 ($socket, $socketl) = ($socketl, $socket) if $opts{udp};
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
443
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
444 $port = $num;
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
445
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
446 for (1 .. 10) {
1236
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
447 $port = int($port / 500) * 500 + int(rand(500)) unless $_ == 1;
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
448
1236
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
449 $lock = $socketl->($port) or next;
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
450 $sock = $socket->($port) and last;
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
451 }
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
452
1236
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
453 die "Port limit exceeded" unless defined $lock and defined $sock;
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
454
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
455 $ports{$num} = {
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
456 port => $port,
1236
93f749c1d5c5 Tests: fixed parallel tests execution with UDP.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1221
diff changeset
457 socket => $lock
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
458 };
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
459
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
460 done:
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
461 return $ports{$num}{socket} if $opts{socket};
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
462 return $ports{$num}{port};
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
463 }
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
464
621
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
465 sub dump_config() {
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
466 my ($self) = @_;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
467
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
468 my $testdir = $self->{_testdir};
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
469
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
470 my @globals = $self->{_test_globals} ?
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
471 () : ('-g', "pid $testdir/nginx.pid; "
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
472 . "error_log $testdir/error.log debug;");
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
473 my $command = "$NGINX -T -p $testdir/ -c nginx.conf "
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
474 . "-e error.log " . join(' ', @globals);
621
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
475
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
476 return qx/$command 2>&1/;
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
477 }
884b2f0c173f Tests: tests for dumped nginx configuration ("nginx -T").
Sergey Kandaurov <pluknet@nginx.com>
parents: 620
diff changeset
478
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
479 sub waitforfile($;$) {
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
480 my ($self, $file, $pid) = @_;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
481 my $exited;
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
482
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
483 # wait for file to appear
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
484 # or specified process to exit
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
485
628
0940773278c7 Tests: backed out previous change, adjusted general timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 621
diff changeset
486 for (1 .. 50) {
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
487 return 1 if -e $file;
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
488 return 0 if $exited;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
489 $exited = waitpid($pid, WNOHANG) != 0 if $pid;
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
490 select undef, undef, undef, 0.1;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
491 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
492
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
493 return undef;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
494 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
495
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
496 sub waitforsocket($) {
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
497 my ($self, $peer) = @_;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
498
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
499 # wait for socket to accept connections
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
500
628
0940773278c7 Tests: backed out previous change, adjusted general timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 621
diff changeset
501 for (1 .. 50) {
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
502 my $s = IO::Socket::INET->new(
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
503 Proto => 'tcp',
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
504 PeerAddr => $peer
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
505 );
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
506
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
507 return 1 if defined $s;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
508
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
509 select undef, undef, undef, 0.1;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
510 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
511
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
512 return undef;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
513 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
514
1206
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
515 sub reload() {
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
516 my ($self) = @_;
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
517
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
518 return $self unless $self->{_started};
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
519
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
520 my $pid = $self->read_file('nginx.pid');
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
521
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
522 if ($^O eq 'MSWin32') {
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
523 my $testdir = $self->{_testdir};
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
524 my @globals = $self->{_test_globals} ?
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
525 () : ('-g', "pid $testdir/nginx.pid; "
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
526 . "error_log $testdir/error.log debug;");
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
527 system($NGINX, '-p', $testdir, '-c', "nginx.conf",
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
528 '-s', 'reload', '-e', 'error.log', @globals) == 0
1206
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
529 or die "system() failed: $?\n";
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
530
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
531 } else {
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
532 kill 'HUP', $pid;
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
533 }
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
534
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
535 return $self;
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
536 }
c99c1f43cb15 Tests: reload() introduced in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1205
diff changeset
537
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
538 sub stop() {
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
539 my ($self) = @_;
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
540
144
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
541 return $self unless $self->{_started};
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
542
1205
c0fa3f818103 Tests: use read_file() in Test::Nginx::stop().
Sergey Kandaurov <pluknet@nginx.com>
parents: 1170
diff changeset
543 my $pid = $self->read_file('nginx.pid');
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
544
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
545 if ($^O eq 'MSWin32') {
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
546 my $testdir = $self->{_testdir};
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
547 my @globals = $self->{_test_globals} ?
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
548 () : ('-g', "pid $testdir/nginx.pid; "
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
549 . "error_log $testdir/error.log debug;");
395
d7d9b4367bab Tests: start nginx prefixed to a temporary directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 392
diff changeset
550 system($NGINX, '-p', $testdir, '-c', "nginx.conf",
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
551 '-s', 'quit', '-e', 'error.log', @globals) == 0
222
5b7883daaf82 Tests: use kill(9, $pid) on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 220
diff changeset
552 or die "system() failed: $?\n";
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
553
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
554 } else {
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
555 kill 'QUIT', $pid;
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
556 }
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
557
1677
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
558 my $exited;
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
559
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
560 for (1 .. 900) {
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
561 $exited = waitpid($pid, WNOHANG) != 0;
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
562 last if $exited;
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
563 select undef, undef, undef, 0.1;
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
564 }
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
565
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
566 if (!$exited) {
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
567 if ($^O eq 'MSWin32') {
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
568 my $testdir = $self->{_testdir};
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
569 my @globals = $self->{_test_globals} ?
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
570 () : ('-g', "pid $testdir/nginx.pid; "
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
571 . "error_log $testdir/error.log debug;");
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
572 system($NGINX, '-p', $testdir, '-c', "nginx.conf",
1790
ba625d5a02e4 Tests: updated try_run() to rely on nginx "-e".
Sergey Kandaurov <pluknet@nginx.com>
parents: 1752
diff changeset
573 '-s', 'stop', '-e', 'error.log', @globals) == 0
1677
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
574 or die "system() failed: $?\n";
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
575
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
576 } else {
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
577 kill 'TERM', $pid;
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
578 }
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
579
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
580 waitpid($pid, 0);
f13ead27f89c Tests: improved stop() to send TERM after QUIT.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1634
diff changeset
581 }
144
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
582
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
583 $self->{_started} = 0;
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
584
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
585 return $self;
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
586 }
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
587
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
588 sub stop_daemons() {
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
589 my ($self) = @_;
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
590
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
591 while ($self->{_daemons} && scalar @{$self->{_daemons}}) {
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
592 my $p = shift @{$self->{_daemons}};
222
5b7883daaf82 Tests: use kill(9, $pid) on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 220
diff changeset
593 kill $^O eq 'MSWin32' ? 9 : 'TERM', $p;
1752
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
594
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
595 my $exited;
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
596
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
597 for (1 .. 50) {
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
598 $exited = waitpid($p, WNOHANG) != 0;
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
599 last if $exited;
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
600 select undef, undef, undef, 0.1;
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
601 }
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
602
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
603 if (!$exited) {
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
604 kill $^O eq 'MSWin32' ? 9 : 'TERM', $p;
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
605 waitpid($p, 0);
ba6e24e38f03 Tests: improved stop_daemons() to send signal again.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1677
diff changeset
606 }
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
607 }
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
608
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
609 return $self;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
610 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
611
467
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
612 sub read_file($) {
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
613 my ($self, $name) = @_;
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
614 local $/;
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
615
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
616 open F, '<', $self->{_testdir} . '/' . $name
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
617 or die "Can't open $name: $!";
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
618 my $content = <F>;
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
619 close F;
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
620
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
621 return $content;
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
622 }
43e05ac6c23c Tests: the read_file function added in Test::Nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents: 460
diff changeset
623
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
624 sub write_file($$) {
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
625 my ($self, $name, $content) = @_;
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
626
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
627 open F, '>' . $self->{_testdir} . '/' . $name
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
628 or die "Can't create $name: $!";
778
9e00ab661e87 Tests: use binmode in write_file().
Sergey Kandaurov <pluknet@nginx.com>
parents: 777
diff changeset
629 binmode F;
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
630 print F $content;
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
631 close F;
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
632
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
633 return $self;
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
634 }
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
635
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
636 sub write_file_expand($$) {
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
637 my ($self, $name, $content) = @_;
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
638
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
639 $content =~ s/%%TEST_GLOBALS%%/$self->test_globals()/gmse;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
640 $content =~ s/%%TEST_GLOBALS_HTTP%%/$self->test_globals_http()/gmse;
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
641 $content =~ s/%%TEST_GLOBALS_STREAM%%/$self->test_globals_stream()/gmse;
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
642 $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms;
969
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
643
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
644 $content =~ s/127\.0\.0\.1:(8\d\d\d)/'127.0.0.1:' . port($1)/gmse;
1edb092149e2 Tests: simplified parallel tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 963
diff changeset
645
951
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
646 $content =~ s/%%PORT_(\d+)%%/port($1)/gmse;
9361c7eddfc1 Tests: parallel tests support.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 947
diff changeset
647 $content =~ s/%%PORT_(\d+)_UDP%%/port($1, udp => 1)/gmse;
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
648
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
649 return $self->write_file($name, $content);
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
650 }
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
651
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
652 sub run_daemon($;@) {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
653 my ($self, $code, @args) = @_;
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
654
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
655 my $pid = fork();
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
656 die "Can't fork daemon: $!\n" unless defined $pid;
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
657
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
658 if ($pid == 0) {
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
659 if (ref($code) eq 'CODE') {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
660 $code->(@args);
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
661 exit 0;
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
662 } else {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
663 exec($code, @args);
195
d73ab4b6ef4a Tests: fix run_daemon() in case of exec() failure.
Maxim Dounin <mdounin@mdounin.ru>
parents: 194
diff changeset
664 exit 0;
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
665 }
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
666 }
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
667
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
668 $self->{_daemons} = [] unless defined $self->{_daemons};
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
669 push @{$self->{_daemons}}, $pid;
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
670
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
671 return $self;
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
672 }
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
673
46
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
674 sub testdir() {
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
675 my ($self) = @_;
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
676 return $self->{_testdir};
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
677 }
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
678
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
679 sub test_globals() {
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
680 my ($self) = @_;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
681
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
682 return $self->{_test_globals}
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
683 if defined $self->{_test_globals};
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
684
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
685 my $s = '';
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
686
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
687 $s .= "pid $self->{_testdir}/nginx.pid;\n";
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
688 $s .= "error_log $self->{_testdir}/error.log debug;\n";
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
689
375
5fdde9f755c9 Tests: a couple of auxiliary environment variables introduced.
Andrei Belov <defan@nginx.com>
parents: 348
diff changeset
690 $s .= $ENV{TEST_NGINX_GLOBALS}
5fdde9f755c9 Tests: a couple of auxiliary environment variables introduced.
Andrei Belov <defan@nginx.com>
parents: 348
diff changeset
691 if $ENV{TEST_NGINX_GLOBALS};
5fdde9f755c9 Tests: a couple of auxiliary environment variables introduced.
Andrei Belov <defan@nginx.com>
parents: 348
diff changeset
692
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
693 $s .= $self->test_globals_modules();
1027
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
694 $s .= $self->test_globals_perl5lib() if $s !~ /env PERL5LIB/;
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
695
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
696 $self->{_test_globals} = $s;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
697 }
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
698
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
699 sub test_globals_modules() {
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
700 my ($self) = @_;
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
701
856
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
702 my $modules = $ENV{TEST_NGINX_MODULES};
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
703
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
704 if (!defined $modules) {
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
705 my ($volume, $dir) = File::Spec->splitpath($NGINX);
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
706 $modules = File::Spec->catpath($volume, $dir, '');
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
707 }
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
708
d39e98893265 Tests: use TEST_NGINX_MODULES to find dynamic modules directory.
Sergey Kandaurov <pluknet@nginx.com>
parents: 854
diff changeset
709 $modules = File::Spec->rel2abs($modules);
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
710 $modules =~ s!\\!/!g if $^O eq 'MSWin32';
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
711
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
712 my $s = '';
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
713
1063
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
714 $s .= "load_module $modules/ngx_http_geoip_module.so;\n"
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
715 if $self->has_module('http_geoip\S+=dynamic');
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
716
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
717 $s .= "load_module $modules/ngx_http_image_filter_module.so;\n"
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
718 if $self->has_module('image_filter\S+=dynamic');
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
719
865
f8f8304c8832 Tests: added support for perl dynamic module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 861
diff changeset
720 $s .= "load_module $modules/ngx_http_perl_module.so;\n"
f8f8304c8832 Tests: added support for perl dynamic module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 861
diff changeset
721 if $self->has_module('perl\S+=dynamic');
f8f8304c8832 Tests: added support for perl dynamic module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 861
diff changeset
722
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
723 $s .= "load_module $modules/ngx_http_xslt_filter_module.so;\n"
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
724 if $self->has_module('xslt\S+=dynamic');
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
725
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
726 $s .= "load_module $modules/ngx_mail_module.so;\n"
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
727 if $self->has_module('mail=dynamic');
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
728
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
729 $s .= "load_module $modules/ngx_stream_module.so;\n"
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
730 if $self->has_module('stream=dynamic');
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
731
1063
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
732 $s .= "load_module $modules/ngx_stream_geoip_module.so;\n"
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
733 if $self->has_module('stream_geoip\S+=dynamic');
d62747c321a6 Tests: support dynamic geoip modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1053
diff changeset
734
854
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
735 return $s;
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
736 }
b237eda210e3 Tests: added support for dynamic modules.
Sergey Kandaurov <pluknet@nginx.com>
parents: 800
diff changeset
737
1027
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
738 sub test_globals_perl5lib() {
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
739 my ($self) = @_;
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
740
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
741 return '' unless $self->has_module('perl');
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
742
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
743 my ($volume, $dir) = File::Spec->splitpath($NGINX);
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
744 my $objs = File::Spec->catpath($volume, $dir, '');
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
745
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
746 $objs = File::Spec->rel2abs($objs);
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
747 $objs =~ s!\\!/!g if $^O eq 'MSWin32';
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
748
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
749 return "env PERL5LIB=$objs/src/http/modules/perl:"
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
750 . "$objs/src/http/modules/perl/blib/arch;\n";
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
751 }
6ef255ed4bbc Tests: set "env PERL5LIB" modules paths fallback for perl module.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1020
diff changeset
752
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
753 sub test_globals_http() {
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
754 my ($self) = @_;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
755
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
756 return $self->{_test_globals_http}
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
757 if defined $self->{_test_globals_http};
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
758
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
759 my $s = '';
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
760
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
761 $s .= "root $self->{_testdir};\n";
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
762 $s .= "access_log $self->{_testdir}/access.log;\n";
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
763 $s .= "client_body_temp_path $self->{_testdir}/client_body_temp;\n";
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
764
243
de7338227832 Tests: removed trailing spaces.
Homutov Vladimir <vl@nginx.com>
parents: 242
diff changeset
765 $s .= "fastcgi_temp_path $self->{_testdir}/fastcgi_temp;\n"
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
766 if $self->has_module('fastcgi');
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
767
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
768 $s .= "proxy_temp_path $self->{_testdir}/proxy_temp;\n"
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
769 if $self->has_module('proxy');
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
770
139
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
771 $s .= "uwsgi_temp_path $self->{_testdir}/uwsgi_temp;\n"
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
772 if $self->has_module('uwsgi');
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
773
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
774 $s .= "scgi_temp_path $self->{_testdir}/scgi_temp;\n"
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
775 if $self->has_module('scgi');
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
776
375
5fdde9f755c9 Tests: a couple of auxiliary environment variables introduced.
Andrei Belov <defan@nginx.com>
parents: 348
diff changeset
777 $s .= $ENV{TEST_NGINX_GLOBALS_HTTP}
5fdde9f755c9 Tests: a couple of auxiliary environment variables introduced.
Andrei Belov <defan@nginx.com>
parents: 348
diff changeset
778 if $ENV{TEST_NGINX_GLOBALS_HTTP};
5fdde9f755c9 Tests: a couple of auxiliary environment variables introduced.
Andrei Belov <defan@nginx.com>
parents: 348
diff changeset
779
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
780 $self->{_test_globals_http} = $s;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
781 }
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
782
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
783 sub test_globals_stream() {
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
784 my ($self) = @_;
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
785
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
786 return $self->{_test_globals_stream}
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
787 if defined $self->{_test_globals_stream};
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
788
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
789 my $s = '';
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
790
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
791 $s .= $ENV{TEST_NGINX_GLOBALS_STREAM}
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
792 if $ENV{TEST_NGINX_GLOBALS_STREAM};
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
793
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
794 $self->{_test_globals_stream} = $s;
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
795 }
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1593
diff changeset
796
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
797 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
798
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
799 sub log_core {
67
5d16f380cd75 Tests: don't output in/out unless TEST_NGINX_VERBOSE set.
Maxim Dounin <mdounin@mdounin.ru>
parents: 51
diff changeset
800 return unless $ENV{TEST_NGINX_VERBOSE};
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
801 my ($prefix, $msg) = @_;
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
802 ($prefix, $msg) = ('', $prefix) unless defined $msg;
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
803 $prefix .= ' ' if length($prefix) > 0;
164
f602276b9bb9 Tests: truncate huge messages while logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 163
diff changeset
804
281
53068d38a3ce Tests: truncate messages to 2048 bytes instead of 4096.
Maxim Dounin <mdounin@mdounin.ru>
parents: 275
diff changeset
805 if (length($msg) > 2048) {
53068d38a3ce Tests: truncate messages to 2048 bytes instead of 4096.
Maxim Dounin <mdounin@mdounin.ru>
parents: 275
diff changeset
806 $msg = substr($msg, 0, 2048)
53068d38a3ce Tests: truncate messages to 2048 bytes instead of 4096.
Maxim Dounin <mdounin@mdounin.ru>
parents: 275
diff changeset
807 . "(...logged only 2048 of " . length($msg)
165
fca70f483608 Tests: fix previous commit (print original message length).
Maxim Dounin <mdounin@mdounin.ru>
parents: 164
diff changeset
808 . " bytes)";
164
f602276b9bb9 Tests: truncate huge messages while logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 163
diff changeset
809 }
f602276b9bb9 Tests: truncate huge messages while logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 163
diff changeset
810
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
811 $msg =~ s/^/# $prefix/gm;
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
812 $msg =~ s/([^\x20-\x7e])/sprintf('\\x%02x', ord($1)) . (($1 eq "\n") ? "\n" : '')/gmxe;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
813 $msg .= "\n" unless $msg =~ /\n\Z/;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
814 print $msg;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
815 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
816
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
817 sub log_out {
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
818 log_core('>>', @_);
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
819 }
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
820
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
821 sub log_in {
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
822 log_core('<<', @_);
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
823 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
824
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
825 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
826
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
827 sub http_get($;%) {
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
828 my ($url, %extra) = @_;
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
829 return http(<<EOF, %extra);
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
830 GET $url HTTP/1.0
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
831 Host: localhost
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
832
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
833 EOF
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
834 }
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
835
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
836 sub http_head($;%) {
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
837 my ($url, %extra) = @_;
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
838 return http(<<EOF, %extra);
41
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
839 HEAD $url HTTP/1.0
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
840 Host: localhost
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
841
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
842 EOF
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
843 }
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
844
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
845 sub http($;%) {
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
846 my ($request, %extra) = @_;
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
847
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
848 my $s = http_start($request, %extra);
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
849
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
850 return $s if $extra{start} or !defined $s;
1865
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
851 return http_end($s, %extra);
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
852 }
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
853
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
854 sub http_start($;%) {
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
855 my ($request, %extra) = @_;
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
856 my $s;
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
857
1865
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
858 my $port = $extra{SSL} ? 8443 : 8080;
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
859
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
860 eval {
96
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 93
diff changeset
861 local $SIG{ALRM} = sub { die "timeout\n" };
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 93
diff changeset
862 local $SIG{PIPE} = sub { die "sigpipe\n" };
628
0940773278c7 Tests: backed out previous change, adjusted general timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 621
diff changeset
863 alarm(8);
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
864
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
865 $s = $extra{socket} || IO::Socket::INET->new(
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
866 Proto => 'tcp',
1865
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
867 PeerAddr => '127.0.0.1:' . port($port),
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
868 %extra
253
f440a8acbf39 Tests: report connection errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 243
diff changeset
869 )
f440a8acbf39 Tests: report connection errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 243
diff changeset
870 or die "Can't connect to nginx: $!\n";
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
871
1865
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
872 if ($extra{SSL}) {
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
873 require IO::Socket::SSL;
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
874 IO::Socket::SSL->start_SSL(
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
875 $s,
1970
6d3a8f4eb9b2 Tests: relaxed SSL version used in testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1963
diff changeset
876 SSL_version => 'SSLv23',
1865
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
877 SSL_verify_mode =>
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
878 IO::Socket::SSL::SSL_VERIFY_NONE(),
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
879 %extra
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
880 )
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
881 or die $IO::Socket::SSL::SSL_ERROR . "\n";
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
882
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
883 log_in("ssl cipher: " . $s->get_cipher());
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
884 log_in("ssl cert: " . $s->peer_certificate('issuer'));
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
885 }
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
886
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
887 log_out($request);
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
888 $s->print($request);
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
889
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
890 select undef, undef, undef, $extra{sleep} if $extra{sleep};
87
f2d09159a8f3 Tests: proxy_store leaving temporary files bug test.
Maxim Dounin <mdounin@mdounin.ru>
parents: 79
diff changeset
891 return '' if $extra{aborted};
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
892
271
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
893 if ($extra{body}) {
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
894 log_out($extra{body});
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
895 $s->print($extra{body});
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
896 }
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
897
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
898 alarm(0);
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
899 };
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
900 alarm(0);
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
901 if ($@) {
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
902 log_in("died: $@");
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
903 return undef;
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
904 }
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
905
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
906 return $s;
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
907 }
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
908
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
909 sub http_end($;%) {
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
910 my ($s) = @_;
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
911 my $reply;
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
912
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
913 eval {
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
914 local $SIG{ALRM} = sub { die "timeout\n" };
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
915 local $SIG{PIPE} = sub { die "sigpipe\n" };
628
0940773278c7 Tests: backed out previous change, adjusted general timeouts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 621
diff changeset
916 alarm(8);
438
60888e2c3f5a Tests: new http_start() and http_end() functions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 415
diff changeset
917
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
918 local $/;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
919 $reply = $s->getline();
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
920
1865
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
921 $s->close();
0e1865aa9b33 Tests: reworked http SSL tests to use IO::Socket::SSL.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1860
diff changeset
922
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
923 alarm(0);
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
924 };
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
925 alarm(0);
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
926 if ($@) {
96
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 93
diff changeset
927 log_in("died: $@");
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
928 return undef;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
929 }
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
930
209
5137f27935b4 Tests: log timeouts in IMAP/POP3/SMTP.
Maxim Dounin <mdounin@mdounin.ru>
parents: 195
diff changeset
931 log_in($reply);
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
932 return $reply;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
933 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
934
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
935 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
936
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
937 sub http_gzip_request {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
938 my ($url) = @_;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
939 my $r = http(<<EOF);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
940 GET $url HTTP/1.1
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
941 Host: localhost
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
942 Connection: close
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
943 Accept-Encoding: gzip
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
944
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
945 EOF
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
946 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
947
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
948 sub http_content {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
949 my ($text) = @_;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
950
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
951 return undef if !defined $text;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
952
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
953 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
954 return undef;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
955 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
956
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
957 my ($headers, $body) = ($1, $2);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
958
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
959 if ($headers !~ /Transfer-Encoding: chunked/i) {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
960 return $body;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
961 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
962
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
963 my $content = '';
1613
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
964 my $len = -1;
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
965
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
966 while ($body =~ /\G\x0d?\x0a?([0-9a-f]+)\x0d\x0a?/gcmsi) {
1613
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
967 $len = hex($1);
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
968 $content .= substr($body, pos($body), $len);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
969 pos($body) += $len;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
970 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
971
1613
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
972 if ($len != 0) {
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
973 $content .= '[no-last-chunk]';
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
974 }
d7ec131d305a Tests: reworked proxy_unfinished.t to use http_content().
Maxim Dounin <mdounin@mdounin.ru>
parents: 1612
diff changeset
975
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
976 return $content;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
977 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
978
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
979 sub http_gzip_like {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
980 my ($text, $re, $name) = @_;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
981
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
982 SKIP: {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
983 eval { require IO::Uncompress::Gunzip; };
601
3a9a7b4f27f0 Tests: properly skip tests if run without IO::Uncompress::Gunzip.
Sergey Kandaurov <pluknet@nginx.com>
parents: 592
diff changeset
984 Test::More::skip(
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
985 "IO::Uncompress::Gunzip not installed", 1) if $@;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
986
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
987 my $in = http_content($text);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
988 my $out;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
989
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
990 IO::Uncompress::Gunzip::gunzip(\$in => \$out);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
991
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
992 Test::More->builder->like($out, $re, $name);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
993 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
994 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
995
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
996 ###############################################################################
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
997
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
998 1;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
999
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1000 ###############################################################################