annotate lib/Test/Nginx.pm @ 312:b639e76ba923

Tests: limit_zone regex updated to follow the module renaming.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 15 Jul 2013 13:06:15 +0400
parents a113f4d55b12
children d48de852157c
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
41
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
14 our @EXPORT = qw/ log_in log_out http http_get http_head /;
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
15 our @EXPORT_OK = qw/ http_gzip_request http_gzip_like /;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
16 our %EXPORT_TAGS = (
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
17 gzip => [ qw/ http_gzip_request http_gzip_like / ]
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
18 );
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21
290
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
22 use File::Path qw/ rmtree /;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23 use File::Temp qw/ tempdir /;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
24 use IO::Socket;
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
25 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
26 use Socket qw/ CRLF /;
27
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
27 use Test::More qw//;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
29 ###############################################################################
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
48
acfafb52d393 Tests: use TEST_NGINX_BINARY to find nginx binary.
Maxim Dounin <mdounin@mdounin.ru>
parents: 46
diff changeset
31 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
32 : '../nginx/objs/nginx';
27
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
33
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
34 sub new {
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
35 my $self = {};
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
36 bless $self;
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
37
296
a113f4d55b12 Tests: fix hang on exit after errors in child processes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 290
diff changeset
38 $self->{_pid} = $$;
a113f4d55b12 Tests: fix hang on exit after errors in child processes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 290
diff changeset
39
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
40 $self->{_testdir} = tempdir(
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
41 'nginx-test-XXXXXXXXXX',
290
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
42 TMPDIR => 1
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
43 )
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
44 or die "Can't create temp directory: $!\n";
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
45 $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
46
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
47 return $self;
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
48 }
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
49
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
50 sub DESTROY {
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
51 my ($self) = @_;
296
a113f4d55b12 Tests: fix hang on exit after errors in child processes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 290
diff changeset
52 return if $self->{_pid} != $$;
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
53 $self->stop();
144
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
54 $self->stop_daemons();
51
d59ae7bab0a6 Tests: cat error log to stdout if TEST_NGINX_CATLOG set.
Maxim Dounin <mdounin@mdounin.ru>
parents: 50
diff changeset
55 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
56 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
57 }
290
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
58 if (not $ENV{TEST_NGINX_LEAVE}) {
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
59 eval { rmtree($self->{_testdir}); };
f781b087b7aa Tests: fixed possible test suite hang on exit.
Vladimir Homutov <vl@nginx.com>
parents: 289
diff changeset
60 }
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
61 }
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
63 sub has($;) {
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
64 my ($self, @features) = @_;
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
65
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
66 foreach my $feature (@features) {
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
67 Test::More::plan(skip_all => "$feature not compiled in")
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
68 unless $self->has_module($feature);
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
69 }
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
70
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
71 return $self;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
72 }
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
73
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
74 sub has_module($) {
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
75 my ($self, $feature) = @_;
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
76
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
77 my %regex = (
237
90af19544dd2 Tests: https sni tests.
Valentin Bartenev <ne@vbart.ru>
parents: 232
diff changeset
78 sni => 'TLS SNI support enabled',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
79 mail => '--with-mail(?!\S)',
33
4f57d57543e1 Tests: range filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 29
diff changeset
80 flv => '--with-http_flv_module',
118
4bf7a819358c Tests: add some embedded perl tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 107
diff changeset
81 perl => '--with-http_perl_module',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
82 charset => '(?s)^(?!.*--without-http_charset_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
83 gzip => '(?s)^(?!.*--without-http_gzip_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
84 ssi => '(?s)^(?!.*--without-http_ssi_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
85 userid => '(?s)^(?!.*--without-http_userid_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
86 access => '(?s)^(?!.*--without-http_access_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
87 auth_basic
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
88 => '(?s)^(?!.*--without-http_auth_basic_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
89 autoindex
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
90 => '(?s)^(?!.*--without-http_autoindex_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
91 geo => '(?s)^(?!.*--without-http_geo_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
92 map => '(?s)^(?!.*--without-http_map_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
93 referer => '(?s)^(?!.*--without-http_referer_module)',
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
94 rewrite => '(?s)^(?!.*--without-http_rewrite_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
95 proxy => '(?s)^(?!.*--without-http_proxy_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
96 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
97 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
98 scgi => '(?s)^(?!.*--without-http_scgi_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
99 memcached
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
100 => '(?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
101 limit_conn
b639e76ba923 Tests: limit_zone regex updated to follow the module renaming.
Sergey Kandaurov <pluknet@nginx.com>
parents: 296
diff changeset
102 => '(?s)^(?!.*--without-http_limit_conn_module)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
103 limit_req
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
104 => '(?s)^(?!.*--without-http_limit_req_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
105 empty_gif
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
106 => '(?s)^(?!.*--without-http_empty_gif_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
107 browser => '(?s)^(?!.*--without-http_browser_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
108 upstream_ip_hash
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
109 => '(?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
110 upstream_least_conn
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
111 => '(?s)^(?!.*--without-http_upstream_least_conn_mod)',
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
112 upstream_keepalive
6cbcfb4ef7ee Tests: correct has() checks for upstream keepalive tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 271
diff changeset
113 => '(?s)^(?!.*--without-http_upstream_keepalive_modu)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
114 http => '(?s)^(?!.*--without-http(?!\S))',
106
7a712d3909ba Tests: add cache availability checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 104
diff changeset
115 cache => '(?s)^(?!.*--without-http-cache)',
121
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
116 pop3 => '(?s)^(?!.*--without-mail_pop3_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
117 imap => '(?s)^(?!.*--without-mail_imap_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
118 smtp => '(?s)^(?!.*--without-mail_smtp_module)',
8ac1faaddd2c Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents: 118
diff changeset
119 pcre => '(?s)^(?!.*--without-pcre)',
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
120 );
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
121
100
9ddc18214854 Tests: arbitrary regexp support in has().
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
122 my $re = $regex{$feature};
9ddc18214854 Tests: arbitrary regexp support in has().
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
123 $re = $feature if !defined $re;
9ddc18214854 Tests: arbitrary regexp support in has().
Maxim Dounin <mdounin@mdounin.ru>
parents: 96
diff changeset
124
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
125 $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
126 if !defined $self->{_configure_args};
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
127
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
128 return ($self->{_configure_args} =~ $re) ? 1 : 0;
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
129 }
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
130
242
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
131 sub has_version($) {
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
132 my ($self, $need) = @_;
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
133
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
134 $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
135 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
136
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
137 $self->{_configure_args} =~ m!nginx version: nginx/([0-9.]+)!;
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
138
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
139 my @v = split(/\./, $1);
284
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
140 my ($n, $v);
242
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
141
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
142 for $n (split(/\./, $need)) {
284
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
143 $v = shift @v || 0;
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
144 return 0 if $n > $v;
8fcc46212e5e Tests: fix has_version() to handle previous branch checks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 281
diff changeset
145 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
146 }
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
147
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
148 return 1;
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
149 }
8f280348d76f Tests: add has_version() method and use it as appropriate.
Maxim Dounin <mdounin@mdounin.ru>
parents: 237
diff changeset
150
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
151 sub has_daemon($) {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
152 my ($self, $daemon) = @_;
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
153
220
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
154 if ($^O eq 'MSWin32') {
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
155 Test::More::plan(skip_all => "win32");
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
156 return $self;
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
157 }
f6f60780f758 Tests: fail has_daemon() on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 219
diff changeset
158
232
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
159 if ($^O eq 'solaris') {
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
160 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
161 unless `command -v $daemon`;
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
162 return $self;
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
163 }
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
164
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
165 Test::More::plan(skip_all => "$daemon not found")
232
4c43b3a0117c Tests: revert 5db96b64cead, use "which" instead of "command -v".
Maxim Dounin <mdounin@mdounin.ru>
parents: 222
diff changeset
166 unless `which $daemon`;
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
167
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
168 return $self;
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
169 }
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
170
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
171 sub plan($) {
28
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
172 my ($self, $plan) = @_;
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
173
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
174 Test::More::plan(tests => $plan);
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
175
8f1519472ece Tests: unbreak and extend has() functionality.
Maxim Dounin <mdounin@mdounin.ru>
parents: 27
diff changeset
176 return $self;
27
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
177 }
fb94a224fef2 Tests: add has() functions for feature testing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 24
diff changeset
178
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
179 sub run(;$) {
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
180 my ($self, $conf) = @_;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
181
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
182 my $testdir = $self->{_testdir};
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
183
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
184 if (defined $conf) {
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
185 my $c = `cat $conf`;
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
186 $self->write_file_expand('nginx.conf', $c);
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
187 }
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
188
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
189 my $pid = fork();
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
190 die "Unable to fork(): $!\n" unless defined $pid;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
191
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
192 if ($pid == 0) {
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
193 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
194 () : ('-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
195 . "error_log $testdir/error.log debug;");
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
196 exec($NGINX, '-c', "$testdir/nginx.conf", @globals)
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
197 or die "Unable to exec(): $!\n";
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
198 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
199
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
200 # wait for nginx to start
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
201
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
202 $self->waitforfile("$testdir/nginx.pid", $pid)
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
203 or die "Can't start nginx";
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
204
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
205 $self->{_started} = 1;
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
206 return $self;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
207 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
208
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
209 sub waitforfile($;$) {
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
210 my ($self, $file, $pid) = @_;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
211 my $exited;
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
212
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
213 # 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
214 # or specified process to exit
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
215
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
216 for (1 .. 30) {
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
217 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
218 return 0 if $exited;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
219 $exited = waitpid($pid, WNOHANG) != 0 if $pid;
50
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
220 select undef, undef, undef, 0.1;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
221 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
222
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
223 return undef;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
224 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
225
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
226 sub waitforsocket($) {
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
227 my ($self, $peer) = @_;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
228
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
229 # wait for socket to accept connections
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
230
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
231 for (1 .. 30) {
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
232 my $s = IO::Socket::INET->new(
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
233 Proto => 'tcp',
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
234 PeerAddr => $peer
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
235 );
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
236
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
237 return 1 if defined $s;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
238
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
239 select undef, undef, undef, 0.1;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
240 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
241
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
242 return undef;
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
243 }
b494fe5b12d1 Tests: add waitforfile() and waitforsocket() functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 49
diff changeset
244
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
245 sub stop() {
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
246 my ($self) = @_;
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
247
144
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
248 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
249
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
250 local $/;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
251 open F, '<' . $self->{_testdir} . '/nginx.pid'
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
252 or die "Can't open nginx.pid: $!";
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
253 my $pid = <F>;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
254 close F;
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
255
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
256 if ($^O eq 'MSWin32') {
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
257 my $testdir = $self->{_testdir};
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
258 my @globals = $self->{_test_globals} ?
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
259 () : ('-g', "pid $testdir/nginx.pid; "
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
260 . "error_log $testdir/error.log debug;");
222
5b7883daaf82 Tests: use kill(9, $pid) on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 220
diff changeset
261 system($NGINX, '-c', "$testdir/nginx.conf", '-s', 'stop',
5b7883daaf82 Tests: use kill(9, $pid) on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 220
diff changeset
262 @globals) == 0
5b7883daaf82 Tests: use kill(9, $pid) on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 220
diff changeset
263 or die "system() failed: $?\n";
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
264
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
265 } else {
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
266 kill 'QUIT', $pid;
219
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
267 }
ce2e23daa1da Tests: minimal win32 support.
Maxim Dounin <mdounin@mdounin.ru>
parents: 209
diff changeset
268
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
269 waitpid($pid, 0);
144
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
270
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
271 $self->{_started} = 0;
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
272
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
273 return $self;
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
274 }
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
275
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
276 sub stop_daemons() {
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
277 my ($self) = @_;
6e11354cae8a Tests: rework stopping to make "open socket left" alerts visible.
Maxim Dounin <mdounin@mdounin.ru>
parents: 139
diff changeset
278
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
279 while ($self->{_daemons} && scalar @{$self->{_daemons}}) {
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
280 my $p = shift @{$self->{_daemons}};
222
5b7883daaf82 Tests: use kill(9, $pid) on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents: 220
diff changeset
281 kill $^O eq 'MSWin32' ? 9 : 'TERM', $p;
289
cbd4f6eca676 Tests: check if started process is alive while starting nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 284
diff changeset
282 waitpid($p, 0);
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
283 }
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
284
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
285 return $self;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
286 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
287
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
288 sub write_file($$) {
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
289 my ($self, $name, $content) = @_;
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
290
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
291 open F, '>' . $self->{_testdir} . '/' . $name
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
292 or die "Can't create $name: $!";
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
293 print F $content;
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
294 close F;
14
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
295
d4b74207a627 Tests: refactor common functions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 12
diff changeset
296 return $self;
12
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
297 }
d19146b30334 Tests: move write_file() into _common.pm.
Maxim Dounin <mdounin@mdounin.ru>
parents: 8
diff changeset
298
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
299 sub write_file_expand($$) {
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
300 my ($self, $name, $content) = @_;
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
301
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
302 $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
303 $content =~ s/%%TEST_GLOBALS_HTTP%%/$self->test_globals_http()/gmse;
15
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
304 $content =~ s/%%TESTDIR%%/$self->{_testdir}/gms;
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
305
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
306 return $self->write_file($name, $content);
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
307 }
c6c36d7a4d90 Tests: support config embedded in test itself.
Maxim Dounin <mdounin@mdounin.ru>
parents: 14
diff changeset
308
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
309 sub run_daemon($;@) {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
310 my ($self, $code, @args) = @_;
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
311
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
312 my $pid = fork();
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
313 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
314
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
315 if ($pid == 0) {
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
316 if (ref($code) eq 'CODE') {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
317 $code->(@args);
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
318 exit 0;
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
319 } else {
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
320 exec($code, @args);
195
d73ab4b6ef4a Tests: fix run_daemon() in case of exec() failure.
Maxim Dounin <mdounin@mdounin.ru>
parents: 194
diff changeset
321 exit 0;
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
322 }
20
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
323 }
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
324
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
325 $self->{_daemons} = [] unless defined $self->{_daemons};
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
326 push @{$self->{_daemons}}, $pid;
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
327
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
328 return $self;
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
329 }
c57e8bd7bfc7 Tests: running simple daemons supplied as coderef.
Maxim Dounin <mdounin@mdounin.ru>
parents: 15
diff changeset
330
46
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
331 sub testdir() {
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
332 my ($self) = @_;
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
333 return $self->{_testdir};
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
334 }
239a346b4913 Tests: add proxy_store basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 45
diff changeset
335
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
336 sub test_globals() {
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
337 my ($self) = @_;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
338
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
339 return $self->{_test_globals}
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
340 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
341
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
342 my $s = '';
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
343
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
344 $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
345 $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
346
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
347 $self->{_test_globals} = $s;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
348 }
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
349
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
350 sub test_globals_http() {
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
351 my ($self) = @_;
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
352
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
353 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
354 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
355
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
356 my $s = '';
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
357
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
358 $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
359 $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
360 $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
361
243
de7338227832 Tests: removed trailing spaces.
Homutov Vladimir <vl@nginx.com>
parents: 242
diff changeset
362 $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
363 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
364
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
365 $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
366 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
367
139
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
368 $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
369 if $self->has_module('uwsgi');
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
370
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
371 $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
372 if $self->has_module('scgi');
8b62dd9b8615 Tests: set temp paths for uwsgi and scgi modules.
Maxim Dounin <mdounin@mdounin.ru>
parents: 133
diff changeset
373
107
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
374 $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
375 }
1c0ec30614c6 Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents: 106
diff changeset
376
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
377 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
378
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
379 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
380 return unless $ENV{TEST_NGINX_VERBOSE};
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
381 my ($prefix, $msg) = @_;
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
382 ($prefix, $msg) = ('', $prefix) unless defined $msg;
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
383 $prefix .= ' ' if length($prefix) > 0;
164
f602276b9bb9 Tests: truncate huge messages while logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 163
diff changeset
384
281
53068d38a3ce Tests: truncate messages to 2048 bytes instead of 4096.
Maxim Dounin <mdounin@mdounin.ru>
parents: 275
diff changeset
385 if (length($msg) > 2048) {
53068d38a3ce Tests: truncate messages to 2048 bytes instead of 4096.
Maxim Dounin <mdounin@mdounin.ru>
parents: 275
diff changeset
386 $msg = substr($msg, 0, 2048)
53068d38a3ce Tests: truncate messages to 2048 bytes instead of 4096.
Maxim Dounin <mdounin@mdounin.ru>
parents: 275
diff changeset
387 . "(...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
388 . " bytes)";
164
f602276b9bb9 Tests: truncate huge messages while logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 163
diff changeset
389 }
f602276b9bb9 Tests: truncate huge messages while logging.
Maxim Dounin <mdounin@mdounin.ru>
parents: 163
diff changeset
390
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
391 $msg =~ s/^/# $prefix/gm;
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
392 $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
393 $msg .= "\n" unless $msg =~ /\n\Z/;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
394 print $msg;
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
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
397 sub log_out {
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
398 log_core('>>', @_);
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
399 }
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
400
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
401 sub log_in {
68
5f56040c39df Tests: smtp xclient tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 67
diff changeset
402 log_core('<<', @_);
5
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 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
406
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
407 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
408 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
409 return http(<<EOF, %extra);
29
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
410 GET $url HTTP/1.0
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
411 Host: localhost
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
412
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
413 EOF
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
414 }
71ea39729fa0 Tests: memcached module generic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 28
diff changeset
415
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
416 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
417 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
418 return http(<<EOF, %extra);
41
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
419 HEAD $url HTTP/1.0
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
420 Host: localhost
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
421
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
422 EOF
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
423 }
1b3c22a87e5d Tests: add some HEAD tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 37
diff changeset
424
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
425 sub http($;%) {
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
426 my ($request, %extra) = @_;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
427 my $reply;
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
428
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
429 eval {
96
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 93
diff changeset
430 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
431 local $SIG{PIPE} = sub { die "sigpipe\n" };
268
8dac281ff522 Tests: increase timeout for putting big chunk in dav_chunked.t.
Valentin Bartenev <vbart@nginx.com>
parents: 253
diff changeset
432 alarm($extra{timeout} || 2);
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
433
237
90af19544dd2 Tests: https sni tests.
Valentin Bartenev <ne@vbart.ru>
parents: 232
diff changeset
434 my $s = $extra{socket} || IO::Socket::INET->new(
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
435 Proto => 'tcp',
45
d68b85def521 Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents: 41
diff changeset
436 PeerAddr => '127.0.0.1:8080'
253
f440a8acbf39 Tests: report connection errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 243
diff changeset
437 )
f440a8acbf39 Tests: report connection errors.
Maxim Dounin <mdounin@mdounin.ru>
parents: 243
diff changeset
438 or die "Can't connect to nginx: $!\n";
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
439
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
440 log_out($request);
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
441 $s->print($request);
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
442
79
d5330d926fac Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents: 77
diff changeset
443 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
444 return '' if $extra{aborted};
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
445
271
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
446 if ($extra{body}) {
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
447 log_out($extra{body});
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
448 $s->print($extra{body});
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
449 }
1a6eef7ac914 Tests: test for r->request_body->buf incorrect reuse.
Maxim Dounin <mdounin@mdounin.ru>
parents: 270
diff changeset
450
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
451 local $/;
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
452 $reply = $s->getline();
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
453
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
454 alarm(0);
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
455 };
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
456 alarm(0);
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
457 if ($@) {
96
ecff5407867c Tests: better handle unexpected connection close from nginx.
Maxim Dounin <mdounin@mdounin.ru>
parents: 93
diff changeset
458 log_in("died: $@");
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
459 return undef;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
460 }
270
f857180657c9 Tests: whitespace, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents: 268
diff changeset
461
209
5137f27935b4 Tests: log timeouts in IMAP/POP3/SMTP.
Maxim Dounin <mdounin@mdounin.ru>
parents: 195
diff changeset
462 log_in($reply);
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
463 return $reply;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
464 }
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
465
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
466 ###############################################################################
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
467
93
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
468 sub http_gzip_request {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
469 my ($url) = @_;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
470 my $r = http(<<EOF);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
471 GET $url HTTP/1.1
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
472 Host: localhost
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
473 Connection: close
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
474 Accept-Encoding: gzip
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
475
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
476 EOF
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
477 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
478
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
479 sub http_content {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
480 my ($text) = @_;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
481
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
482 return undef if !defined $text;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
483
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
484 if ($text !~ /(.*?)\x0d\x0a?\x0d\x0a?(.*)/ms) {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
485 return undef;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
486 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
487
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
488 my ($headers, $body) = ($1, $2);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
489
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
490 if ($headers !~ /Transfer-Encoding: chunked/i) {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
491 return $body;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
492 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
493
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
494 my $content = '';
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
495 while ($body =~ /\G\x0d?\x0a?([0-9a-f]+)\x0d\x0a?/gcmsi) {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
496 my $len = hex($1);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
497 $content .= substr($body, pos($body), $len);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
498 pos($body) += $len;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
499 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
500
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
501 return $content;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
502 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
503
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
504 sub http_gzip_like {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
505 my ($text, $re, $name) = @_;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
506
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
507 SKIP: {
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
508 eval { require IO::Uncompress::Gunzip; };
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
509 Test::More->builder->skip(
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
510 "IO::Uncompress::Gunzip not installed", 1) if $@;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
511
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
512 my $in = http_content($text);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
513 my $out;
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
514
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
515 IO::Uncompress::Gunzip::gunzip(\$in => \$out);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
516
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
517 Test::More->builder->like($out, $re, $name);
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
518 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
519 }
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
520
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
521 ###############################################################################
5276d85d5040 Tests: add basic gzip tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 87
diff changeset
522
5
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
523 1;
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
524
4d75bdb05ecf Tests: some generic code and ssi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
525 ###############################################################################