Mercurial > hg > nginx-tests
annotate uwsgi.t @ 801:d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
This complements tests for scgi_pass, fastcgi_pass, uwsgi_pass with variables
that evaluate to an implicit upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 09 Dec 2015 18:59:26 +0300 |
parents | dc2f8aac0553 |
children | eca9b1d19021 |
rev | line source |
---|---|
168 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Test for uwsgi backend. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http uwsgi/)->has_daemon('uwsgi')->plan(4) |
168 | 25 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
241
diff
changeset
|
29 daemon off; |
168 | 30 |
31 events { | |
32 } | |
33 | |
34 http { | |
35 %%TEST_GLOBALS_HTTP%% | |
36 | |
37 server { | |
38 listen 127.0.0.1:8080; | |
39 server_name localhost; | |
40 | |
41 location / { | |
42 uwsgi_pass 127.0.0.1:8081; | |
43 uwsgi_param SERVER_PROTOCOL $server_protocol; | |
44 uwsgi_param HTTP_X_BLAH "blah"; | |
45 } | |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
46 |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
47 location /var { |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
48 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
|
49 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
|
50 } |
168 | 51 } |
52 } | |
53 | |
54 EOF | |
55 | |
56 $t->write_file('uwsgi_test_app.py', <<END); | |
57 | |
58 def application(env, start_response): | |
59 start_response('200 OK', [('Content-Type','text/plain')]) | |
60 return "SEE-THIS" | |
61 | |
62 END | |
63 | |
363
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
64 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
|
65 my @uwsgiopts = (); |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
66 |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
67 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
|
68 # 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
|
69 push @uwsgiopts, '--plugin', 'python'; |
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 |
98f3a8568b0c
Tests: try to load python plugin if uwsgi has no wsgi option.
Sergey Budnevitch <sb@waeme.net>
parents:
249
diff
changeset
|
72 $t->run_daemon('uwsgi', '--socket', '127.0.0.1:8081', @uwsgiopts, |
168 | 73 '--wsgi-file', $t->testdir() . '/uwsgi_test_app.py', |
74 '--logto', $t->testdir() . '/uwsgi_log'); | |
75 | |
76 $t->run(); | |
77 | |
174
c8169c827d18
Tests: use waitoforsocket() as uwsgi startup may take a while.
Maxim Dounin <mdounin@mdounin.ru>
parents:
168
diff
changeset
|
78 $t->waitforsocket('127.0.0.1:8081') |
c8169c827d18
Tests: use waitoforsocket() as uwsgi startup may take a while.
Maxim Dounin <mdounin@mdounin.ru>
parents:
168
diff
changeset
|
79 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
|
80 |
168 | 81 ############################################################################### |
82 | |
83 like(http_get('/'), qr/SEE-THIS/, 'uwsgi request'); | |
84 unlike(http_head('/head'), qr/SEE-THIS/, 'no data in HEAD'); | |
85 | |
86 like(http_get_headers('/headers'), qr/SEE-THIS/, | |
87 'uwsgi request with many ignored headers'); | |
88 | |
801
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
89 like(http_get('/var?b=127.0.0.1:8081'), qr/SEE-THIS/, 'uwsgi with variables'); |
d95c4b8e5517
Tests: more tests for passing requests to host given by expression.
Sergey Kandaurov <pluknet@nginx.com>
parents:
590
diff
changeset
|
90 |
168 | 91 ############################################################################### |
92 | |
93 sub http_get_headers { | |
590
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
363
diff
changeset
|
94 my ($url, %extra) = @_; |
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
363
diff
changeset
|
95 return http(<<EOF, %extra); |
168 | 96 GET $url HTTP/1.0 |
97 Host: localhost | |
98 X-Blah: ignored header | |
99 X-Blah: ignored header | |
100 X-Blah: ignored header | |
101 X-Blah: ignored header | |
102 X-Blah: ignored header | |
103 X-Blah: ignored header | |
104 X-Blah: ignored header | |
105 X-Blah: ignored header | |
106 X-Blah: ignored header | |
107 X-Blah: ignored header | |
108 X-Blah: ignored header | |
109 X-Blah: ignored header | |
110 X-Blah: ignored header | |
111 X-Blah: ignored header | |
112 X-Blah: ignored header | |
113 X-Blah: ignored header | |
114 X-Blah: ignored header | |
115 X-Blah: ignored header | |
116 X-Blah: ignored header | |
117 | |
118 EOF | |
119 } | |
120 | |
121 ############################################################################### |