annotate uwsgi.t @ 1606:e4e0695552ed

Tests: fixed stream_proxy_ssl_conf_command.t. The stream_proxy_ssl_conf_command.t test used stream return module to return the response. Since this ignores actual request, but the perl test code used http_get(). This might result in the request being sent after the response is returned and the connection closed by the server, resulting in RST being generated and no response seen by the client at all. Fix is to use "stream(...)->read()" instead of http_get(), so no request is sent at all, eliminating possibility of RST being generated.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 10 Nov 2020 05:03:29 +0300
parents f069dd7ba5a7
children 1d7932bc2847
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
1 #!/usr/bin/perl
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
2
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
3 # (C) Maxim Dounin
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
4
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
5 # Test for uwsgi backend.
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
6
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
7 ###############################################################################
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
8
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
9 use warnings;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
10 use strict;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
11
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
12 use Test::More;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
13
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
14 BEGIN { use FindBin; chdir($FindBin::Bin); }
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
15
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
16 use lib 'lib';
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
17 use Test::Nginx;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
18
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
19 ###############################################################################
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
20
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
21 select STDERR; $| = 1;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
22 select STDOUT; $| = 1;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23
802
eca9b1d19021 Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 801
diff changeset
24 my $t = Test::Nginx->new()->has(qw/http uwsgi/)->has_daemon('uwsgi')->plan(5)
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
25 ->write_file_expand('nginx.conf', <<'EOF');
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
26
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
27 %%TEST_GLOBALS%%
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
28
249
6a0d934950bc Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents: 241
diff changeset
29 daemon off;
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
30
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
31 events {
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
32 }
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
33
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
34 http {
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
35 %%TEST_GLOBALS_HTTP%%
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
36
802
eca9b1d19021 Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 801
diff changeset
37 upstream u {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
38 server 127.0.0.1:8081;
802
eca9b1d19021 Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 801
diff changeset
39 }
eca9b1d19021 Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 801
diff changeset
40
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
41 server {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
42 listen 127.0.0.1:8080;
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
43 server_name localhost;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
44
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
45 location / {
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
46 uwsgi_pass 127.0.0.1:8081;
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
47 uwsgi_param SERVER_PROTOCOL $server_protocol;
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
48 uwsgi_param HTTP_X_BLAH "blah";
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
49 }
801
d95c4b8e5517 Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents: 590
diff changeset
50
d95c4b8e5517 Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents: 590
diff changeset
51 location /var {
d95c4b8e5517 Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents: 590
diff changeset
52 uwsgi_pass $arg_b;
d95c4b8e5517 Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents: 590
diff changeset
53 uwsgi_param SERVER_PROTOCOL $server_protocol;
d95c4b8e5517 Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents: 590
diff changeset
54 }
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
55 }
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
56 }
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
57
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
58 EOF
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
59
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
60 $t->write_file('uwsgi_test_app.py', <<END);
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
61
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
62 def application(env, start_response):
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
63 start_response('200 OK', [('Content-Type','text/plain')])
1480
d23d959713b5 Tests: Python 3.7 (PEP 3333) compatibility in uwsgi tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 974
diff changeset
64 return b"SEE-THIS"
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
65
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
66 END
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
67
363
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
68 my $uwsgihelp = `uwsgi -h`;
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
69 my @uwsgiopts = ();
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
70
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
71 if ($uwsgihelp !~ /--wsgi-file/) {
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
72 # uwsgi has no python support, maybe plugin load is necessary
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
73 push @uwsgiopts, '--plugin', 'python';
1598
f069dd7ba5a7 Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1480
diff changeset
74 push @uwsgiopts, '--plugin', 'python3';
363
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
75 }
98f3a8568b0c Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents: 249
diff changeset
76
1598
f069dd7ba5a7 Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1480
diff changeset
77 open OLDERR, ">&", \*STDERR; close STDERR;
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
78 $t->run_daemon('uwsgi', '--socket', '127.0.0.1:' . port(8081), @uwsgiopts,
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
79 '--wsgi-file', $t->testdir() . '/uwsgi_test_app.py',
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
80 '--logto', $t->testdir() . '/uwsgi_log');
1598
f069dd7ba5a7 Tests: compatibility with uwsgi python package on Fedora Linux.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1480
diff changeset
81 open STDERR, ">&", \*OLDERR;
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
82
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
83 $t->run();
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
84
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
85 $t->waitforsocket('127.0.0.1:' . port(8081))
174
c8169c827d18 Tests: use waitoforsocket() as uwsgi startup may take a while.
Maxim Dounin <mdounin@mdounin.ru>
parents: 168
diff changeset
86 or die "Can't start uwsgi";
c8169c827d18 Tests: use waitoforsocket() as uwsgi startup may take a while.
Maxim Dounin <mdounin@mdounin.ru>
parents: 168
diff changeset
87
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
88 ###############################################################################
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
89
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
90 like(http_get('/'), qr/SEE-THIS/, 'uwsgi request');
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
91 unlike(http_head('/head'), qr/SEE-THIS/, 'no data in HEAD');
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
92
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
93 like(http_get_headers('/headers'), qr/SEE-THIS/,
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
94 'uwsgi request with many ignored headers');
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
95
974
882267679006 Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 952
diff changeset
96 like(http_get('/var?b=127.0.0.1:' . port(8081)), qr/SEE-THIS/,
952
e9064d691790 Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 802
diff changeset
97 'uwsgi with variables');
802
eca9b1d19021 Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents: 801
diff changeset
98 like(http_get('/var?b=u'), qr/SEE-THIS/, 'uwsgi with variables to upstream');
801
d95c4b8e5517 Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents: 590
diff changeset
99
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
100 ###############################################################################
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
102 sub http_get_headers {
590
dc2f8aac0553 Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 363
diff changeset
103 my ($url, %extra) = @_;
dc2f8aac0553 Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 363
diff changeset
104 return http(<<EOF, %extra);
168
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
105 GET $url HTTP/1.0
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106 Host: localhost
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
113 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
114 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
115 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
116 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
117 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
118 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
119 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
120 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
121 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
122 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
123 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
124 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
125 X-Blah: ignored header
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
126
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
127 EOF
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
128 }
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
129
e9133938a5d3 Tests: add uwsgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
130 ###############################################################################